.NET & Application Pools

[Note: I use the term web application in this post. This is not the Visual Studio 'Web Application' but rather refers to any .NET content that runs under IIS.]

Application pools, on the surface, look to be a wonderful addition to IIS 6.0. However, unless you have a good understanding of how application pools work with regard the .NET framework, you could end up causing some serious damage. This is something that is usually explained in literature, but the impact of it is typically glossed over, so I’m here to help fill the gap.

Application pools are a way to allow web application isolation on a web server. An application pool is just a container for a worker process (w3wp.exe), which is in charge of serving requests for all the applications that it manages. A single application pools can have multiple worker processes running under it (termed a web garden), but a single worker process cannot run across multiple pools. An application pool can, theoretically, manage an infinite amount of applications, but you also have the ability to create more than one, and you can assign your application to any available pool using the IIS console (or programmatically).

iisconsole.jpg

Application pools create isolation in the sense that if there is a failure in one pool (the w3wp.exe process dies), it will not affect the other pools that are running. These failures occur at times, and in the case of web servers that serve multiple web sites, isolation is key – you don’t want your site to go down because someone else killed your worker process. Application pools also have the ability to run under different user credentials, which means you can manage access to certain resources using application pools. Application pools are also agnostic of .NET framework version – the virtual directory is the item that dictates both what
application pool manages it, and the version of the framework that it runs under. You assign an application to an application pool using IIS console.

One strange, and potentially dangerous, thing about application pools is that they can only run one version of the .NET framework at once. This
means that if you try serving an application that runs under .NET 1.1 and another under .NET 2.0 simultaneously, then they had better be under different application pools. What happens if you try running both at the same time? The first application that gets served will work, regardless of the framework version it runs under. The second will fail, and all subsequent requests for either application will fail. The worker process ends up dying an untimely death. How is this an issue? Well here are two very likely scenarios where this behavior can cause problems:

  • A user has just added a new virtual directory and has not been diligent on choosing the correct application pool
  • A web application has been upgraded to a newer version of the .NET framework, and the user updates the framework version on the virtual directory but fails to change to a more appropriate application pool.

So, how does one mitigate risk of application pool failure under this scenario? One of the most important things to do is to make sure you have
at least one application pool for every framework version that your web server supports. Typically, I do this by including the framework version in
the application pool name, for example naming two pools ‘ExamplePool 1.1′ and ‘ExamplePool 2.0.’ This greatly simplifies management. A good way to
see what version of an application pool that you are running under is to open the IIS console and expand the tree node that corresponds to the pool
you are interested in. This will allow you to see what applications are running under a given pool.

apppools.jpg

There are other options available to mitigate the risks of this issue hurting you, but all have significant drawbacks. First, you could create a
different application pool for every application you run. For a few applications this is fine. However, since each pool contains a w3wp.exe
process, a large number of active pools could slow down your server. Second, you could leverage a w3wp.exe process ping that will restart failed
processes. The drawback here is that this only works on one-off instances: a real issue will continuously kill the w3wp.exe process very quickly after
it is restarted. A third option is that you could make sure your application does not target a particular .NET framework version (they are supposedly pretty compatible, but there can be breaking changes from time to time). However, this means that you had the time to test your existing codebase before you introduce a new framework version. The only solution that I’ve found to work is pure diligence.

Waiting Patiently for Halo 3

So, I’ve never been the biggest Halo fan in the world. I thought the first one was a bit overrated when compared to PC FPSs of the time. Halo 2 was a true gem, but I never really got into the online aspect all that much. I believe online mode is where the true zealots for a game are born.

As far as FPSs on the 360, I can remember being really, really gung-ho for Gears of War last year, and only slightly less excited for Bioshock last month. However, I’ve taken a different approach with Halo 3 – I kind of ignored it for a long time. I decided against the beta, and I just glanced over news items rather than reading them in depth. The first thing that really got to me was hearing about the 4-player co-op play. Since then, the anticipation has been slowly building to a point where I’m really ready for the full Halo 3 experience. I can’t wait to try out the flamethrower and clobber some grunts with 3 of my friends as I inevitably save the entire world.

This year is certainly shaping up to be a banner FPS year, starting with The Darkness, then Bioshock, and Halo 3 and the Orange Box looming on the horizon. And that’s just FPSs! There are at least as many compelling titles in other genres on the Wii and 360, and the PS3 lineup is slowly working itself up (maybe I’ll find a good enough reason to buy one finally). This is truly a great year for gaming. Will it surpass last year? I dunno – it’s hard to top a year that has the hype of console releases, but hell, who knows…

Describable, Smart Enumerations Helper Class (C# 2.0)

Update – Check out this article for the latest and greatest.

I’ve decided to post an EnumerationHelpers class written in C# 2.0. This class allows you to easily work with description tags on your enumeration values, and search them to pull the appropriate value out based on the description. This is great for times like when you want an enumeration to control a picklist but you don’t want to have to create a switch statement to match the displayed value with the enumeration value. In that respect, it also effectively isolates you from change (but, displayed values never change… right…). Here is an example of how to use it:

enum Status
{
 [Description("This is a new item")] New,
 [Description("This is an existing item")] Existing,
 [Description("This is an old item")] Old,
 DescriptionUnavailable
};

Status s = Status.New;

// Returns "This is a new item"
string strDescription = EnumerationHelpers.GetEnumDescription(s);

// Returns Status.Existing
s = EnumerationHelpers.GetEnumValueFromDescription("This is an existing item");

// Returns Status.Old
s = EnumerationHelpers.GetEnumValueFromDescription("Old");

// Returns "DescriptionUnavailable"
strDescription = EnumerationHelpers.GetEnumDescription(Status.DescriptionUnavailable);

As you can see, it becomes a fairly trivial task to implement describable enumerations. You can also see that it relies on the power of generics, and is type-safe. Feel free to take a look under the hood, and to use it for whatever needs you have. All I ask is that you leave in the copyright on the top of the code. Included in the package is a .csproj which includes the helper class and a set of NUnit tests that can help show you the ropes with the class. It’s available here!

Mexico Pictures are Up

Iguana Ate a Bird?

I’ve posted some pictures from my trip to Riviera Maya this past August. This was about a week before Hurricane Dean came storming in. I went with a good friend, K for short, and we stayed at the Occidental Grand Flamenco Xcaret resort. If you wanted to take a look at beautiful Mexico, have at it. This is just a subset of the 350+ pics I have, and I’ll probably occasionally add pics as I get around to it. I’ll share my thoughts on the wonderful country of Mexico in a future post.

And the Winner Is…

Here is something else that came out of my work on my senior thesis. We had to present our papers, and my wacky department chair decided that we needed to sell the content. So, she made us create posters for our presentations. So, instead of working on content, I decided to come up with the most kick-ass poster out there. I won by a landslide :)

Genetic Algorithm Poster

Content! We need CONTENT!

So, there hasn’t been all that much going on with the site since I got the space. Blame life, I guess. So, instead of working hard to come up with new content, I decided to republish existing content. Specifically, here lies within my undergraduate senior thesis on the Genetic Algorithm. It was done in 2000-01 I believe, and covered the thesis requirements for both my Computer Science and Mathematics degrees. There was a sample application that modeled the GA to go with the paper, but I think it’s long gone. Besides, I don’t even want to see the Java code I wrote in college – I would have a fit, I’m sure!

Either way, if you’re looking for a good read, here it is:

Paper

Bibliography