太多的TimerQueueTimer对象被分配并占用大量内存

我有一个运行的Web API,该API与Service Bus连接,以将消息写入主题并部署在Service Fabric中。我看到异常高的内存使用率,并且大多数内存被TimerQueueTimer对象占用,尽管我没有明确初始化任何Timer。

太多的TimerQueueTimer对象被分配并占用大量内存

追溯到如何创建这些计时器时,会看到以下名称空间:

microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryModules.<Modules>k__BackingField ->
microsoft.ApplicationInsights.Extensibility.Implementation.snapshottingList<microsoft.ApplicationInsights.Extensibility.ITelemetryModule>.Collection ->
System.Collections.Generic.List<microsoft.ApplicationInsights.Extensibility.ITelemetryModule>._items ->
microsoft.ApplicationInsights.Extensibility.ITelemetryModule[16] at [4] ->
microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule.timer ->
microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.Implementation.Timer.Timer.timer ->
System.Threading.Timer.m_timer

--------------------------------------------

microsoft.Azure.ServiceBus.TopicClient.<ServiceBusConnection>k__BackingField ->
microsoft.Azure.ServiceBus.ServiceBusConnection.<Connectionmanager>k__BackingField ->
microsoft.Azure.Amqp.FaultTolerantAmqpObject<microsoft.Azure.Amqp.AmqpConnection>.taskCompletionSource ->
System.Threading.Tasks.TaskCompletionSource<microsoft.Azure.Amqp.AmqpConnection>.m_task ->
System.Threading.Tasks.Task<microsoft.Azure.Amqp.AmqpConnection>.m_result ->
microsoft.Azure.Amqp.AmqpConnection.heartBeat ->
microsoft.Azure.Amqp.AmqpConnection+HeartBeat+TimedHeartBeat.heartBeatTimer ->
System.Threading.Timer.m_timer ->
System.Threading.TimerHolder.m_timer ->
System.Threading.TimerQueueTimer.m_next ->

--------------------------------------------

microsoft.ServiceFabric.Services.Communication.Client.CommunicationClientCache<Serviceclient.HttpCommunicationClient>.cachecleanupTimer ->
System.Threading.Timer.m_timer ->
System.Threading.TimerHolder.m_timer   

不确定为什么不收集这些计时器,而所有这些计时器都位于Gen2中。在一段时间内,内存峰值增加,应用程序变得无响应。什么时候永远不会收集此类Timer对象?

emrick 回答:太多的TimerQueueTimer对象被分配并占用大量内存

我们最近也遇到了类似的问题,主要是与TimerQueueTimer和Application Insights有关。

我们将Microsoft.ApplicationInsights.AspNetCore从2.3.0升级到2.8.2,看来已经解决了该问题。很有可能是#690,已在v2.4.0中修复。

本文链接:https://www.f2er.com/3112469.html

大家都在问