Should we use “workstation” garbage collection or “server” garbage collection?

时光总嘲笑我的痴心妄想 提交于 2019-11-26 15:56:03

问题


I have a large multi-threaded C# application running on a multi-core 4-way server. Currently we're using "server mode" garbage collection. However testing has shown that workstation mode GC is quicker.

MSDN says:

Managed code applications that use the server API receive significant benefits from using the server-optimized garbage collector (GC) instead of the default workstation GC.

Workstation is the default GC mode and the only one available on single-processor computers. Workstation GC is hosted in console and Windows Forms applications. It performs full (generation 2) collections concurrently with the running program, thereby minimizing latency. This mode is useful for client applications, where perceived performance is usually more important than raw throughput.

The server GC is available only on multiprocessor computers. It creates a separate managed heap and thread for each processor and performs collections in parallel. During collection, all managed threads are paused (threads running native code are paused only when the native call returns). In this way, the server GC mode maximizes throughput (the number of requests per second) and improves performance as the number of processors increases. Performance especially shines on computers with four or more processors.

But we're not seeing performance shine!!!! Has anyone got any advice?


回答1:


It's not explained very well, but as far as I can tell, the server mode is synchronous per core, while the workstation mode is asynchronous.

In other words, the workstation mode is intended for a small number of long running applications that need consistent performance. The garbage collection tries to "stay out of the way" but, as a result, is less efficient on average.

The server mode is intended for applications where each "job" is relatively short lived and handled by a single core (edit: think multi threaded web server). The idea is that each "job" gets all the cpu power, and gets done quickly, but that occasionally the core stops handling requests and cleans up memory. So in this case the hope is that GC is more efficient on average, but the core is unavailable while its running, so the application needs to be able to adapt to that.

In your case it sounds like, because you have a single application whose threads are relatively coupled, you're fitting better into the model expected by the first mode rather than the second.

But that's all just after-the-fact justification. Measure your system's performance (as ammoQ said, not your GC performance, but how well you application behaves) and use what you measure to be best.




回答2:


.NET 4.5 introduces concurrent server garbage collection.

http://msdn.microsoft.com/en-us/library/ee787088.aspx

specify <gcServer enabled="true"/> 
specify <gcConcurrent enabled="true"/> (this is the default so can be omitted)

And there is the new SustainedLowLatencyMode;

In the .NET Framework 4.5, SustainedLowLatency mode is available for both workstation and server GC. To turn it on, set the GCSettings.LatencyMode property to GCLatencyMode.SustainedLowLatency.




回答3:


Server: Your program is the only significant application on the machine and needs the lowest possible latency for GCs.

Workstation: You have a UI or share the machine with other important process



来源:https://stackoverflow.com/questions/1707240/should-we-use-workstation-garbage-collection-or-server-garbage-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!