.NET垃圾收集器的麻烦。块15-40分钟 [英] .NET Garbagecollector trouble. Blocks for 15-40 mins

查看:72
本文介绍了.NET垃圾收集器的麻烦。块15-40分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些事实:
我们开发了wcf服务,作为客户端和数据库之间的一层。
它是自托管的,并作为Windows服务运行。

该服务保留了多个缓存,其中最大的内存大约为1-2GB。总内存使用量通常约为5-8GB。
连接是双工的,使用tcp协议,序列化是用protobuf-net完成的。我们连接的客户端数量通常在1000-1500之间。
服务器是一个8核心的64位内存的新型64位Xeon处理器,运行时间仅为服务。



问题:经过x倍的时间后,从一天到一周,这个服务变得非常缓慢。需要0.5秒的请求可能需要一分钟。这种行为持续15-40分钟,直到服务重启。



我们做了什么:
我们检查了网络和网络连接服务器并没有问题。在此期间,CPU使用率从f.eks有所增加。平均30%至平均40-50%。
我们已经进行了内存转储,并且在代码中没有逻辑锁定会阻止用户,并且根本没有太多活动。
我们最新的领先者是垃圾收集器。在perfmon中,我们可以看到gc%时间总是超过90%,(90-97%),收集计数增加。 GC0和GC1。我们怀疑有一个阻塞的GC2也在运行,但我们不得不重新启动服务,因为这是在生产中,所以在我们运行perfmon的5分钟窗口期间它不计数。内存使用量为7.6 Gb。
注意:调用未完成的上升,所以调用到达那里,但服务不处理它们。



我的问题是,垃圾收集器是否可以进入它会持续运行并阻止超过15分钟?或者问题可能与其他问题有关?

我们的服务在工作站模式和延迟模式下运行GC:Interactive
现在我们已将其更改为Server和SustainedLowLatency,并希望这会有所帮助。如果它的垃圾收集器还有什么我们可以做的吗?



编辑:大量的内存使用是由设计决定的,缓存中的数据很大,更多的内存可用。

解决方案

过多的垃圾回收通常是由代码问题引起的。您可以在短时间内创建太多的对象,或者在不释放内存的情况下继续分配内存。



实际上有一个可在MSDN上获得的广泛清单,它可以帮助您诊断问题。



一个非常大的GC2意味着其中的对象存活了多个垃圾回收,这意味着它们会长时间保存在内存中。这可能是你问题的根源。也许有一个缓存机制可以使用一些调整/保留策略(删除长时间不用的数据)。


Some facts: We have developed wcf service that acts as a layer between clients and the database. It's selfhosted and runs as a windows service.

The service keeps several caches, where the largest are about 1-2gb in memory. Total memory usage is usually about 5-8gb. Connections are duplex and uses tcp protocol and the serialization is made with protobuf-net. Our connected client count usually range from 1000-1500. The server is a 8-core xeon of newish model with 64gb memory and runs nothing more then the service.

The problem: After x amount of time, it has been everywhere from a day to a week the service gets extremely slow. Requests that takes 0.5 seconds can take over a minute. This behaviour goes on for 15-40 minutes or til the service is restarted.

What we have done : We have checked the network and network connection to the server and there is no problem. CPU utilization goes up somewhat during this time from f.eks. 30% avg to 40-50% avg. We have taken memory dumps and there are no logical locks in code that blocks the users and not much activity at all. Our latest lead is the Garbage collector. In perfmon we can see that "% time in gc" is constantly over 90%,(90-97%) and the collection counts rises. Both GC0 and GC1. We suspect there is a blocking GC2 running also but we had to restart the service as this is in production so it didn't count up during the 5min window we ran perfmon. Memory usage was 7,6 Gb. Note : Calls outstanding rises so the calls get there but the service does not handle them.

My questions are, Can the garbage collector get in a state where it runs and blocks constantly for over 15minutes? or are the problem probably related to some other issue?

Our service ran GC in workstation mode and latencymode : Interactive We have now changed this to Server and SustainedLowLatency and hopes this will help somewhat. Are there anything else we can do if its the garbage collector?

Edit : The large memory usage is by design, the data in the caches is that large and there is lots of more memory available.

解决方案

Excessive garbage collection is often caused by code issues. You either create too many objects in a short time, or you keep allocating memory without releasing it.

There is actually an extensive checklist available on MSDN that should help you diagnose the problem.

A very large GC2 means that the objects in there survived multiple garbage collections, which means they are kept in memory for a longer period of time. That could be the root cause of your issue. Maybe there is a caching mechanism that could use some tuning / retention policy (remove data that isn't used for a long time).

这篇关于.NET垃圾收集器的麻烦。块15-40分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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