Is GCLatencyMode.LowLatency a good choice?

I have a Windows C # service acting as a server, the service contains some large (> 8Gb) in-memory data structures and provides remote search methods for clients.

The avg search operation is performed at <200ms, and the service processes up to 20 requests / sec.

I often notice severe performance degradation (> 6000ms) within seconds

My best guess is that server threads from time to time are stopped by gen2 garbage collection.

I am considering switching from a gc server to a gc workstation and overlaying a search method on it to prevent GC during requests.

static protected void DoLowLatencyAction(Action action) { GCLatencyMode oldMode = GCSettings.LatencyMode; try { GCSettings.LatencyMode = GCLatencyMode.LowLatency; // perform time-sensitive actions here action(); } finally { GCSettings.LatencyMode = oldMode; } } 

Is that a good idea?

Under what conditions will the GC be executed anyway inside the low latency block?

Note. I am running an x64 server with 8 cores

thanks

+4
source share
3 answers

I have not used GCLatencyMode , so I can not comment on whether using is a good idea or not.

However, are you sure you are using a GC server? By default, Windows services use the GC workstation.

I had a similar problem before in windows service and setting the GC server mode using:

 <configuration> <runtime> <gcServer enabled="true" /> </runtime> </configuration> 

in the service file app.config resolved it.

Read this post from Tess Ferranddes' blog for more details.

+8
source

I am surprised that your search method even runs GC if the 8GB data structure is static (doesn't change much by adding or removing from it) and all you do is search, then you should just try to avoid highlighting temporary objects within your search method (if possible). Creating objects is what starts the GC, and if you have a data structure that rarely changes, then it makes sense to avoid sharing the GC (or delay it as much as possible).

GCSettings.LowLatency does this, gives the GC a hint to make greedy collections to avoid the Gen2 collection while LowLatency is set. What this does as a side effect is to force the GC to gather outside the region where the LowLatency mode is set, and can lead to poor performance (in this case, you can try the GC server mode).

+1
source

This doesn't seem like a great idea. At some point, GC will ignore your hint and make a collection anyway.

I believe that you will have much better success by actually profiling and optimizing your service. Run PerfView (a free, great, Microsoft tool) on your server while you work. See who owns the nasty objects and how long specific long-running GC events have been running.

0
source

All Articles