We had a situation where a web application was utilising near 100% of CPU all the time under light load and it was proving very hard to reduce this significantly through code optimisation. We were performance testing and profiling, but only seeing marginal gains.
The infrastructure that was hosting the web application was as follows:
- Virtual Server (Hosted via VMWare Server) running Windows Server 2003 64 bit
- .Net 3.5
- Dual Virtual CPUs
- 2 Gb of memory.
Now I am not a big fan of virtualisation for hosting high performance web sites but we were stuck with this. At any rate, we had consistently high CPU utilisation for seemingly no real reason. Some of the most simple requests were generating high CPU usage.
After some investigation, and also the help of a friend and very smart dude, Scott Forsyth (who works for Orcsweb a high profile web hosting company) we decided to try setting Internet Information Services to 32 bit mode to see if any difference was seen.
To cut a long story short, we changed Internet Information Services to run in 32 bit mode. This simple switch, yielded significant lower CPU utilisation and in some case, almost cut the CPU utilisation in half!
Why would this be so? Well, it turns out there are a few reasons for this. Probably the primary reason is the fact the we get less information within the level 1 cache of the processor because of the increased structure size (pointers are bigger) within 64 bit systems. The same information in a 64 bit system occupies more memory than its 32 bit counterpart, therefore we can fit less into the processor cache. More information on this can be found here.
Its really easy to change IIS to 32 bit mode. The steps are:
- To enable 32 bit mode on IIS in 64 bit windows, at a command prompt type:
cscript %SYSTEMDRIVE%\inetpub\adminscripts\adsutil.vbs SET W3SVC/AppPools/Enable32bitAppOnWin64 1
- Once this is done, 32 bit mode is enabled but we need to ensure that the 32 bit DLL’s are used as IIS will still have the 64 bit DLL’s defined for the ISAPI handler. To do this, all we have to do is re-register ASP.NET. At a command prompt, simply type:
- Finally, just make sure the status ASP.NET version 2.0.50727 (32-bit) in the web services extension, within IIS, is set to allowed.
(More information on this process can be found here http://support.microsoft.com/kb/894435)
And that’s it. A few lines of script, and we had effectively reduced CPU utilisation by somewhere in between 30% and 50%!
So my rule is this, If you are:
- Running Windows server in 64 bit mode.
- Running a standard .Net web application
- Do not need a large memory address space (ie. over 4 gigabytes)
- Have no special 64 bit optimisations
Then this change will yield immediate performance improvements in your application, and in some cases (dependent on what your application does), yield significant performance improvements.