Patch Tuesday tip (especially useful for VM users)

Christian Nesmark

After updating the .NET framework through Windows Update, you could experience a temporary performance degradation. For users of multiple VMs, this can be a big problem. Here is a tip for speeding up the process.

First, a little background. My virtual environment is rigged for several types of developement - ASP.NET MVC, Windows Phone, Windows 8, and SharePoint. I therefore have multiple virtual machines:

  • sauron: The all-seeing eye (AD controller)
  • tirith: Where the library is (SQL Server)
  • mordor: SharePoint
  • moria: Where cool stuff is crafted
  • addition to a couple of customer-specific VMs.

Whenever there has been an update for the .NET Framework, there will be a certain process running for several hours on all of these machines. It is called mscorsvw.exe (.NET Runtime Optimization Service), and it precompiles all the DLLs in the .NET framework. It is somewhat considerate, as it runs only when there is no user activity, which is fine in a single-machine scenario. But I can only work on one VM at any give time, so the three others just run in the background (AD, SQL etc). Naturally, the optimization service running in these VMs does not detect my activity, and thus consumes a lot of resources, lowering my laptop's performance, and making the cooling fan sound like a take-off is imminent.

This can be quite annoying, so I'm like...

Get on with it!

ngen.exe to the rescue

Luckily, there is a way to speed up this process, and give the compilation process top priority. In the *%windir%\Microsoft.NET\Framework{version}* folder, there is a gem called ngen.exe (Native Image Generator). What you can do with this, is to force execution of the compilation queue. To do that, run the command with a parameter, executeQueuedItems.

This is true both for the 32-bit and 64-bit versions of the framework, so you need to run ngen.exe for all installed versions. The best thing to do is to create a script to ensure all versions get compiled. Note: The script must be run in a command prompt in Administrator mode.

%windir%\Microsoft.NET\Framework\v4.0.30319\ngen.exe executeQueuedItems
%windir%\Microsoft.NET\Framework64\v4.0.30319\ngen.exe executeQueuedItems

The last time I ran that script in all my VMs simultanously, my i7 quad core finally got a real challenge.

quadcore ngen

As you can see, your computer is practically unusable during this process, but if you start the script just before you go to lunch, it will be done by the time you get back. Neat.

I also found a more in-depth article about this on the .NET Framework Blog. I recommend it if you like to learn more about pre-compiling native images.

VM, WU">
comments powered by Disqus