- Frugal Cafe
- Posts
- FC28 How many heaps do you really need?
FC28 How many heaps do you really need?
right sizing managed heap
Now that I’m using my dev box with 16 physical cores and 24 logical cores, I noticed ILSpy.exe is using more memory. I captured a memory dump to look into it. It turns out ILSpy.exe is using server GC mode, 24 heaps, with Gen0 being the biggest at 84%. That is spoiled rich kid life. There is no real need for ILSpy.exe to use server GC. Even if server GC is needed, you need to restrict heap count to a reasonable number.
Choosing the right GC mode and heap count are important performance considerations for cloud services. Mistakes are often made in this area which can affect the performance of the whole machine. This is especially important when you have multiple heavy weight processes on the same machine.
Here are my suggestions:
Consider core count on the machine: N
Consider among of memory on the machine you want to reserve for managed heaps: M
Calculate memory per code: m = M / N
For every process, if its managed heap is less than m, use work-station GC mode, if it’s n times m, use server GC with n heaps.
Change the settings, get new managed heap sizes, and re-adjust.
In my case, I have 24 cores, 128 gb of memory, suppose I want to use 48 gb for managed heap, so m = M / N = 2 gb. Processes with managed heap smaller than 2 gb should be running in work-station GC mode.
Here is the configuration file for ilspy.exe:
Just change it to false, or remove it. You could also specify heap count yourself as in:
.Net Framework has similar settings:
For processes with small managed heaps, switching to work-station GC mode, or reduce heap count could be more efficient for both memory and CPU usages. The real benefit of using server GC is really in reducing GC latency.