iis – High CPU Utilization by w3wp.exe Due to GC Issue?

central-processing-unitgarbage-collectingiis

I've inherited a website that uses a lot of session state. We've recently experienced continuous high CPU ~95-100% for prolonged period of times.

When debugging using DebugDiag, it shows that there was ~3gb on the Large Object Heap which I believe is collected in Gen 2 by the GC and could be a cause of the high cpu.

I have practically zero experience debugging such scenarios, but does the above sound a plausible reason for the high CPU?

Thanks.

Best Answer

You can verify if GC is the issue by using Performance Monitor and the '.NET Memory\% Time in GC' performance counter. If you only have one .NET process on the server, you can just use the _total instance. Otherwise you'll have to find the instance that has a matching process ID and watch that one (though be aware that the instance name for you application can change on the fly if any apps start up or shut down).

If spikes in this counter correspond to the CPU spikes, garbage collection is your issue--you will need to look for leaks, allocate fewer objects, keep things small enough to keep them out of the LOH, keep them around less time, reuse them, and/or eliminate destructors. Each of these things will reduce time spent locked up in GC. Ironically, too much caching can make your site inconsistently unresponsive, as cached items eventually end up in heap 2, and request processing pauses while the GC sweeps through every item in heap 2. As memory pressure increases, the frequency of these lockouts increases until eventually your requests get completely starved out.

Related Topic