.NET Runtime Optimization Service, Who is eating CPU cookies?

Dec 24, 2013

I recently configured a trial Windows Server 2012 R2 VM to start fiddling with it and use it later for other not so important things.

One beautiful winter night, I observed that even if I am not doing single nasty thing on this machine, still I see my CPU usage 100%. Whoa, who is eating my cookies?

At first glance in task manger, I found two alien processes gobbling CPU and some RAM

  • .Net Runtime Optimization Service (also known as mscorsvw.exe)
  • Microsoft Common Language Run-time native compiler

.NET Runtime optimization service in task manager

Microsoft Common Language Runtime native compiler in task manager

Until I was not aware of it, I thought it has to do something with .Net framework, I guess and the name suggest it is optimizing something.

After few reads by people at Microsoft and others I finally understood the importance of mscorsvw.exe and why / when does it run. I probably will not repeat the whole story and violate Web DRY rules. But goal of this write up is understanding Microsoft’s efforts to make sure your app is treated in best way possible. Also wanted to point everybody to understand vital role of NGEN.exe to make things fairy for your application.

Few points I can summarize:

  • The .Net framework (including mscorlib) is regularly optimized by Microsoft using the above service to make sure you get the best out of the system libraries and this is also done for your installed managed application.

  • Its not annoying or now and then thing, it runs only in two cases:

    • when .Net framework is installed and
    • when windows update for .Net framework are pushed on your system.
  • NGEN exist since .Net framework 1 and pretty much doing work since then, now from Windows 8 NGET is taken to next level with new feature they call as AutoNGEN. This feature provides behavior to NGET to work in smarter way and during idle hours to reduce you task blocking situations.

This is important to understand and know about because you might run into problems as Development team or as DevOps team figuring out why your production application is not responding or running slow. This can be or might be a reason (for few minutes though) and also draws attention to the facts about planning your .NET framework related Windows Update to make sure you have a smooth sailing deployments and production environment.

Rich Lander covering the whole story on MSDN Blog and handshake with NGEN tool.