High CPU Usage by .NET Runtime Optimization Service

Costas

Administrator
Staff member
This problem usually appears randomly but it can also occur after an update is installed to .NET Framework. The process’s executable is mscorsvw.exe and it will be displayed in Task Manager under that name or as .NET Runtime Optimization Service. It doesn’t run so often and it’s a service that runs to optimize .NET Framework which, in return, makes sure apps and programs dependent on it run faster.

The official answer is that the process needs to recompile its libraries and that it should only run when the computer is idle. Microsoft also states that the process shouldn’t take more than a couple of minutes.


It’s not recommended to end this process immediately.

Optimizing the process :


1st way

JavaScript:
//on x86 systems
cd c:\Windows\Microsoft.NET\Framework\v4.0.30319

//on x64 systems
cd c:\Windows\Microsoft.NET\Framework64\v4.0.30319

ngen.exe executequeueditems


2nd way (microsoft github repository)
Download by click 'raw' then right-click 'save as' then double click the file to run
you can use the WSF
https://github.com/Microsoft/dotnet/blob/master/tools/DrainNGENQueue/DrainNGenQueue.wsf

for advanced users there is also a Powershell script:
https://github.com/microsoft/dotnet/blob/master/tools/DrainNGENQueue/DrainNGenQueue.ps1


src - https://appuals.com/fix-high-cpu-usage-by-net-runtime-optimization-service/
 

Costas

Administrator
Staff member
The Native Image Generator (Ngen.exe) is a tool that improves the performance of managed applications. Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer. The runtime can use native images from the cache instead of using the just-in-time (JIT) compiler to compile the original assembly.

By default there is a service for this
WTfYubB.png


how is working :
the windows, store a queue of assemblies exist to GAC, under the keys :

JavaScript:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\NGenQueue\WIN32\Default
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\NGenQueue\WIN64\Default

any subkey is an information for an assembly needed to have a unmanage image. The most common in use is mscorlib.ni.dll (unmanaged) by its origin mscorlib.dll (managed)...

 

Run manually the NET Runtime Optimization Service
the user has to run for x86 and x64 respectively

JavaScript:
cd /d C:\Windows\Microsoft.NET\Framework\v4.0.30319

ngen.exe executeQueuedItems

cd /d C:\Windows\Microsoft.NET\Framework64\v4.0.30319

ngen.exe executeQueuedItems

once then execution ended the registry keys under Default deleted and unmanaged files generated to the following locations :

JavaScript:
//please use DOS, because Windows will say folder doesnt exist
cd /d C:\Windows\assembly\NativeImages_v2.0.50727_32
cd /d C:\Windows\assembly\NativeImages_v2.0.50727_64
cd /d C:\Windows\assembly\NativeImages_v4.0.30319_32
cd /d C:\Windows\assembly\NativeImages_v4.0.30319_64

all unmanaged files have the suffix *ni.dll (aka native image)...

from now on if you run a .NET application will get +50% boost!!



refs :
https://www.reddit.com/r/TronScript/comments/9fufo7/suggestion_to_executequeueditems_for_net/
https://appuals.com/fix-high-cpu-usage-by-net-runtime-optimization-service/
https://kb.vmware.com/s/article/2069188

#ngen #ni #mscorlib.ni.dll
 
Top