我们应该使用“工作站"吗?垃圾收集或“服务器";垃圾收集? [英] Should we use "workstation" garbage collection or "server" garbage collection?

查看:18
本文介绍了我们应该使用“工作站"吗?垃圾收集或“服务器";垃圾收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型多线程 C# 应用程序在多核 4 路服务器上运行.目前我们正在使用服务器模式".垃圾收集.但是测试表明,工作站模式 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 的托管代码应用程序从使用服务器优化的垃圾收集器 (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 模式,也是单处理器计算机上唯一可用的模式.Workstation 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 仅在多处理器计算机上可用.它为每个处理器创建一个单独的托管堆和线程,并并行执行集合.在收集期间,所有托管线程都被暂停(运行本机代码的线程仅在本机调用返回时才暂停).这样,服务器 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 能力,并很快完成,但有时核心会停止处理请求并清理内存.所以在这种情况下,希望 GC 平均效率更高,但核心在运行时不可用,因此应用程序需要能够适应这种情况.

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.

这篇关于我们应该使用“工作站"吗?垃圾收集或“服务器";垃圾收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆