Getting better performance in web apps with a few lines of script

Published Saturday, June 27, 2009 8:53 PM

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:

  1. 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
  2. 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:
    %SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe –i
  3. 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%!

Conclusion

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.

by Glav
Filed under: , , ,

Comments

# flalar said on Monday, June 29, 2009 2:20 AM

Informative post! How would this change affect the total memory available for caching etc? Experiencing the same issue, but are caching alot of data in the asp.net cache.

# Simon said on Monday, June 29, 2009 2:59 AM

Good tip. However, don't you think this might be caused by the virtualization layer rather than being a general solution? I assume your physical machine is still running in 64-bit natively, so 32-bit instructions coming from your VM will still be handled in 64-bit, won't they?

# Glav said on Monday, June 29, 2009 7:00 AM

Flalar, it depends. If you think you are allocating over 2Gb of memory in terms of cache, then perhaps. What you will find is that ASP.NET actually has a lot lower limit before memory thresholds are triggered. I suspect the amount will vary though.

Simon, we initially thought that the VM infrastructure was to blame (in fact was almost hoping as I dont like VM's for performance related reasons), and there is undoubtedly a perf hit using VM's, but we did the same on physical boxes, and saw similar substantial gains.

# Peter said on Monday, June 29, 2009 9:54 AM

Have you tried doing the same with Windows Server 2008 64 bit?

# Glav said on Tuesday, June 30, 2009 8:18 AM

Peter,

No not specifically, but I do know that you will still see gains on 2008. Not as significant, but they do exist in a little greater than 50% of scenarios (where mem < 4gb as per above).

Leave a Comment

(required) 
(required) 
(optional)
(required) 

This Blog

Syndication