c# - 我们应该使用 "workstation"垃圾回收还是 "server"垃圾回收?

标签 c# .net garbage-collection

我有一个大型多线程 C# 应用程序在多核 4 路服务器上运行。目前我们正在使用“服务器模式”垃圾收集。然而,测试表明工作站模式 GC 更快。

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.

但我们没有看到性能闪耀!!!!有人有什么建议吗?

最佳答案

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

换句话说,工作站模式适用于需要稳定性能的少量长时间运行的应用程序。垃圾收集试图“避开”,但结果是平均效率较低。

服务器模式适用于每个“作业”相对较短且由单个内核处理的应用程序(编辑:想想多线程网络服务器)。这个想法是每个“工作”都获得所有的 cpu 能力,并快速完成,但偶尔核心会停止处理请求并清理内存。因此在这种情况下,希望 GC 的平均效率更高,但核心在运行时不可用,因此应用程序需要能够适应这一点。

在您的情况下,这听起来像是,因为您有一个线程相对耦合的应用程序,所以您更适合第一种模式而不是第二种模式所期望的模型。

但这只是事后证明。衡量您的系统性能(如 ammoQ 所说,不是您的 GC 性能,而是您的应用程序的表现如何)并使用您衡量的最佳结果。

关于c# - 我们应该使用 "workstation"垃圾回收还是 "server"垃圾回收?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1707240/

相关文章:

c# - Objective-C/iPhone 中的公钥加密

c# - 在 gridview 的 boundfield 中找不到值?

c# - 正则表达式查找具有实际数学值的百分号

c# - 通过 TCP 接收数据 : MemoryStream contains more data than expected

java - Java HttpSession 对象的生命周期是什么?

r - 在 R Studio 中,我遇到 Java 内存不足(对于 RWeka)

C# - 实现具有两个公共(public)接口(interface)的私有(private)类,然后转换为它们两个?馊主意?

c# - 从 WPF 中的 Image 标记修改图像

.net - 如何将 IQueryable<string> 转换为字符串数组?

java - 为什么存在WeakHashMap,却没有WeakSet?