我们是否应该使用"工作站"垃圾收集或QUOT;服务器"垃圾收集?垃圾、工作站、服务器、QUOT

2023-09-02 10:30:24 作者:可怜沒ィ嗳

我运行一个多核心的4路服务器上的大量多线程C#应用程序。目前我们使用的是服务器模式垃圾回收。然而测试表明,工作站模式GC更快。

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说:

管理$使用该服务器API C $ C应用程序使用的服务器优化的垃圾收集器(GC)而不是默认的工作站GC收到显著的好处。

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.

工作站是默认的GC模式和可用单处理器计算机唯一的一个。工作站GC托管在控制台和Windows窗体应用程序。它执行完整(第2代)收集的同时正在运行的程序,从而最大限度地减少等待时间。这种模式适用于客户端应用程序,其中感知性能通常比原始吞吐量更重要是有用的。

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.

服务器GC仅在多处理器计算机。它为每个处理器创建一个独立的托管堆和线程并行执行的集合。在收集,所有托管线程暂停(运行原生code线程暂停,只有当本地调用返回)。在这种方式中,服务器的GC模式最大化吞吐量(每秒请求的数目)并提高性能随着处理器数量的增加。性能尤其是闪耀着四个或更多处理器的计算机上。

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?

推荐答案

这不是很好的解释,但据我所知,在服务器模式为每个内核同步,而工作站模式是异步的。

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.

服务器模式是为应用程序,其中每个工作是比较短暂的,处理由单核(编辑:思多线程Web服务器)。其思想是每个工作得到所有的CPU处理能力,并得到迅速进行,但偶尔核心停止处理请求和清除存储器。因此,在这种情况下,希望的是,气相色谱是平均更有效,但其核心是,同时它的运行不可用,所以应用程序需要能够适应该

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.

但是,这一切都只是后的,事实理由。测量你的系统的性能(如ammoQ说,不是你的GC性能,但如何好,你应用程序的行为),并使用你衡量是最好的。

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.