可能的事件处理ASP.NET中的泄漏
我们的ASP.NET Web应用程序似乎有一些泄漏,因为它使用了异常数量的内存和许多打开的手柄。从sysinternals使用的手柄来检查所有类型事件。每小时大约有200k+手柄。
我知道这不是点击等事件处理等,并且与锁,计时器和其他内容有关,因此检测到它们的来源并不容易。
最重要的项目
...
00007ff853c4a620 117529 10342552 System.ServiceModel.Description.MessagePartDescription
00007ff856578df8 19388 10547616 XXX.Providers.ISettingsItem`1[[System.String, mscorlib]][]
00007ff8a9eb8150 222047 10658256 System.Threading.ManualResetEvent
00007ff8a9e3fe28 450451 10810824 System.Runtime.Remoting.Messaging.CallContextSecurityData
00007ff84f63f788 221904 12426624 System.Runtime.Caching.CacheExpires
00007ff8a9ec3738 222171 12441576 System.Collections.Hashtable+HashtableEnumerator
00007ff84d384fd8 195746 14093712 System.Xml.Serialization.ElementAccessor
00007ff8a9eb43a0 226703 14508992 System.Threading.TimerCallback
00007ff855b9cc28 212423 16993840 System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[XXX.Configuration.ModelValue, XXX.Configuration]]
00007ff850c48960 102466 17214288 XXX.ModelDefinition.Models.ComputedRisk
00007ff84eb81f00 314190 17594640 System.Xml.Linq.XAttribute
00007ff8a9eb4670 551441 17646112 System.Decimal
00007ff84f63a568 221904 17752320 System.Runtime.Caching.MemoryCacheStore
00007ff8a9eb9fe0 449588 17983520 System.Collections.Stack
00007ff8a9e395e0 226835 19961480 System.Threading.TimerQueueTimer
00007ff84d38bcf8 165198 21145344 System.Xml.Serialization.MemberMapping
00007ff84f6b1020 221904 21302784 System.Runtime.Caching.UsageBucket
00007ff8a9ec9d80 1098447 26362728 System.Object
00007ff8a9ec4010 450469 32433768 System.Runtime.Remoting.Messaging.LogicalCallContext
00007ff8a9eb5b00 451141 39700408 System.Threading.ExecutionContext
00007ff8a9eca8f0 22780 49571828 System.Char[]
00007ff84f63fd40 221904 58582656 System.Runtime.Caching.ExpiresBucket[]
00007ff8a9ecd190 740049 59203920 System.Collections.Hashtable
00007ff8a9ec9e18 541051 60908584 System.Object[]
00007ff8a9eb13c8 961209 145744128 System.Collections.Hashtable+bucket[]
00007ff855ba6980 212423 181843056 System.Collections.Generic.Dictionary`2+Entry[[System.String, mscorlib],[XXX.Configuration.ModelValue, XXX.Configuration]][]
00007ff8a9ecc088 6978827 313669564 System.Int32[]
00007ff8a97b7ce8 4129359 330348720 System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]]
00007ff850bf6e60 4082662 522580736 XXX.Configuration.ModelValue
00007ff8a9ec97a0 6549932 622915972 System.String
00007ff84f63fcb0 6657120 639083520 System.Runtime.Caching.ExpiresBucket
00007ff8a9ecea48 65101 716832124 System.Byte[]
0000019223a6cd70 1331493 5145008822 Free
Total 48770037 objects
检查转储并使用!dumpheap -stat
我得到了我只想知道的 ,有这么多expirebucket
条目是正常的吗?这是否意味着所有手柄都应该与缓存有关?
有什么提示如何获取更多信息?
更新
检查gcroot
,似乎与
0:000> !gcroot 000001f413bb7c98
Thread 5394:
0000009a997be3d0 00007ffc2291a702 System.Net.TimerThread.ThreadProc()
rdi: (interior)
-> 000002001336bfd8 System.Object[]
-> 000001ffd34177d8 System.Collections.Generic.Dictionary`2[[System.Object, mscorlib],[System.Collections.Generic.List`1[[Microsoft.Win32.SystemEvents+SystemEventInvokeInfo, System]], mscorlib]]
-> 000001ffd34178d0 System.Collections.Generic.Dictionary`2+Entry[[System.Object, mscorlib],[System.Collections.Generic.List`1[[Microsoft.Win32.SystemEvents+SystemEventInvokeInfo, System]], mscorlib]][]
-> 000001ffd3417868 System.Collections.Generic.List`1[[Microsoft.Win32.SystemEvents+SystemEventInvokeInfo, System]]
-> 000001ffd3417950 Microsoft.Win32.SystemEvents+SystemEventInvokeInfo[]
-> 000001ffd3417930 Microsoft.Win32.SystemEvents+SystemEventInvokeInfo
-> 000001f8d33730b0 System.Web.AspNetSynchronizationContext
-> 000001f8d3373198 System.Web.AspNetSynchronizationContext+State
-> 000001f8d33730d8 System.Web.Util.SynchronizationHelper
-> 000001f8d3367058 ASP.global_asax
-> 000001fed33686c0 System.Web.HttpApplicationState
-> 000001fed3368768 System.Collections.ArrayList
-> 000001fad33b5c98 System.Object[]
-> 000001fad33b5c78 System.Collections.Specialized.NameObjectCollectionBase+NameObjectEntry
-> 000001fad33b49d0 Microsoft.Practices.Unity.UnityContainer
-> 000001fad33b4b60 Microsoft.Practices.ObjectBuilder2.LifetimeContainer
-> 000001fad33b4b78 System.Collections.Generic.List`1[[System.Object, mscorlib]]
-> 000001fe13396698 System.Object[]
-> 000001fb1339e080 Microsoft.Practices.Unity.ContainerControlledLifetimeManager
-> 000001fb1339dda8 Microsoft.Extensions.Logging.LoggerFactory
-> 000001fb1339de88 System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[Microsoft.Extensions.Logging.Logger, Microsoft.Extensions.Logging]]
-> 000001f5537004c0 System.Collections.Generic.Dictionary`2+Entry[[System.String, mscorlib],[Microsoft.Extensions.Logging.Logger, Microsoft.Extensions.Logging]][]
-> 000001f4d3626690 Microsoft.Extensions.Logging.Logger
-> 000001f4d36266b8 Microsoft.Extensions.Logging.LoggerInformation[]
-> 000001f4d36266f0 Serilog.Extensions.Logging.SerilogLogger
-> 000001fb1339df68 Serilog.Extensions.Logging.SerilogLoggerProvider
-> 000001fb1339dfe0 Serilog.Core.Logger
-> 000001fb1339dd60 Serilog.Core.Logger
-> 000001fb1339d5a8 Serilog.Core.Sinks.SafeAggregateSink
-> 000001fb1339d5c0 Serilog.Core.ILogEventSink[]
-> 000001fb1339af98 Serilog.Sinks.Http.Private.NonDurable.HttpSink
-> 000001fb1339b098 Serilog.Sinks.Http.Private.Time.PortableTimer
-> 000001fb1339b120 System.Threading.Timer
-> 000001fb1339b1f0 System.Threading.TimerHolder
-> 000001fb1339b140 System.Threading.TimerQueueTimer
...
300k x System.Threading.TimerQueueTimer
...
-> 000001f413bb8670 System.Threading.TimerQueueTimer
-> 000001f413bb8610 System.Threading.TimerCallback
-> 000001f413bb73e8 System.Runtime.Caching.CacheExpires
-> 000001f413bb7420 System.Runtime.Caching.ExpiresBucket[]
-> 000001f413bb7c98 System.Runtime.Caching.ExpiresBucket
Failed to enumerate GC references.
Failed to walk thread 25ec
Legacy Webforms应用程序相同,带有Enterprise Library
unity 版本3.5。由于使用记录器serilog
。
Our Asp.Net web application seems to have some leaks, because it uses unusual amount of memory and many opened handles. Used handle from SysInternals to check all are of type Event. There are around 200k+ handles per hour.
I know it is not event handle like clicks etc. and it is related to locks, timers and another things, so it is not easy to detect source of them.
Checked dump and using !dumpheap -stat
I got the most significant items
...
00007ff853c4a620 117529 10342552 System.ServiceModel.Description.MessagePartDescription
00007ff856578df8 19388 10547616 XXX.Providers.ISettingsItem`1[[System.String, mscorlib]][]
00007ff8a9eb8150 222047 10658256 System.Threading.ManualResetEvent
00007ff8a9e3fe28 450451 10810824 System.Runtime.Remoting.Messaging.CallContextSecurityData
00007ff84f63f788 221904 12426624 System.Runtime.Caching.CacheExpires
00007ff8a9ec3738 222171 12441576 System.Collections.Hashtable+HashtableEnumerator
00007ff84d384fd8 195746 14093712 System.Xml.Serialization.ElementAccessor
00007ff8a9eb43a0 226703 14508992 System.Threading.TimerCallback
00007ff855b9cc28 212423 16993840 System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[XXX.Configuration.ModelValue, XXX.Configuration]]
00007ff850c48960 102466 17214288 XXX.ModelDefinition.Models.ComputedRisk
00007ff84eb81f00 314190 17594640 System.Xml.Linq.XAttribute
00007ff8a9eb4670 551441 17646112 System.Decimal
00007ff84f63a568 221904 17752320 System.Runtime.Caching.MemoryCacheStore
00007ff8a9eb9fe0 449588 17983520 System.Collections.Stack
00007ff8a9e395e0 226835 19961480 System.Threading.TimerQueueTimer
00007ff84d38bcf8 165198 21145344 System.Xml.Serialization.MemberMapping
00007ff84f6b1020 221904 21302784 System.Runtime.Caching.UsageBucket
00007ff8a9ec9d80 1098447 26362728 System.Object
00007ff8a9ec4010 450469 32433768 System.Runtime.Remoting.Messaging.LogicalCallContext
00007ff8a9eb5b00 451141 39700408 System.Threading.ExecutionContext
00007ff8a9eca8f0 22780 49571828 System.Char[]
00007ff84f63fd40 221904 58582656 System.Runtime.Caching.ExpiresBucket[]
00007ff8a9ecd190 740049 59203920 System.Collections.Hashtable
00007ff8a9ec9e18 541051 60908584 System.Object[]
00007ff8a9eb13c8 961209 145744128 System.Collections.Hashtable+bucket[]
00007ff855ba6980 212423 181843056 System.Collections.Generic.Dictionary`2+Entry[[System.String, mscorlib],[XXX.Configuration.ModelValue, XXX.Configuration]][]
00007ff8a9ecc088 6978827 313669564 System.Int32[]
00007ff8a97b7ce8 4129359 330348720 System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Object, mscorlib]]
00007ff850bf6e60 4082662 522580736 XXX.Configuration.ModelValue
00007ff8a9ec97a0 6549932 622915972 System.String
00007ff84f63fcb0 6657120 639083520 System.Runtime.Caching.ExpiresBucket
00007ff8a9ecea48 65101 716832124 System.Byte[]
0000019223a6cd70 1331493 5145008822 Free
Total 48770037 objects
I just want to know, is it normal to have so many ExpireBucket
entries? Does it mean all handles should be related to caching?
Any tips how to get more info?
UPDATE
Checked GCRoot
and seems to be the same pattern
0:000> !gcroot 000001f413bb7c98
Thread 5394:
0000009a997be3d0 00007ffc2291a702 System.Net.TimerThread.ThreadProc()
rdi: (interior)
-> 000002001336bfd8 System.Object[]
-> 000001ffd34177d8 System.Collections.Generic.Dictionary`2[[System.Object, mscorlib],[System.Collections.Generic.List`1[[Microsoft.Win32.SystemEvents+SystemEventInvokeInfo, System]], mscorlib]]
-> 000001ffd34178d0 System.Collections.Generic.Dictionary`2+Entry[[System.Object, mscorlib],[System.Collections.Generic.List`1[[Microsoft.Win32.SystemEvents+SystemEventInvokeInfo, System]], mscorlib]][]
-> 000001ffd3417868 System.Collections.Generic.List`1[[Microsoft.Win32.SystemEvents+SystemEventInvokeInfo, System]]
-> 000001ffd3417950 Microsoft.Win32.SystemEvents+SystemEventInvokeInfo[]
-> 000001ffd3417930 Microsoft.Win32.SystemEvents+SystemEventInvokeInfo
-> 000001f8d33730b0 System.Web.AspNetSynchronizationContext
-> 000001f8d3373198 System.Web.AspNetSynchronizationContext+State
-> 000001f8d33730d8 System.Web.Util.SynchronizationHelper
-> 000001f8d3367058 ASP.global_asax
-> 000001fed33686c0 System.Web.HttpApplicationState
-> 000001fed3368768 System.Collections.ArrayList
-> 000001fad33b5c98 System.Object[]
-> 000001fad33b5c78 System.Collections.Specialized.NameObjectCollectionBase+NameObjectEntry
-> 000001fad33b49d0 Microsoft.Practices.Unity.UnityContainer
-> 000001fad33b4b60 Microsoft.Practices.ObjectBuilder2.LifetimeContainer
-> 000001fad33b4b78 System.Collections.Generic.List`1[[System.Object, mscorlib]]
-> 000001fe13396698 System.Object[]
-> 000001fb1339e080 Microsoft.Practices.Unity.ContainerControlledLifetimeManager
-> 000001fb1339dda8 Microsoft.Extensions.Logging.LoggerFactory
-> 000001fb1339de88 System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[Microsoft.Extensions.Logging.Logger, Microsoft.Extensions.Logging]]
-> 000001f5537004c0 System.Collections.Generic.Dictionary`2+Entry[[System.String, mscorlib],[Microsoft.Extensions.Logging.Logger, Microsoft.Extensions.Logging]][]
-> 000001f4d3626690 Microsoft.Extensions.Logging.Logger
-> 000001f4d36266b8 Microsoft.Extensions.Logging.LoggerInformation[]
-> 000001f4d36266f0 Serilog.Extensions.Logging.SerilogLogger
-> 000001fb1339df68 Serilog.Extensions.Logging.SerilogLoggerProvider
-> 000001fb1339dfe0 Serilog.Core.Logger
-> 000001fb1339dd60 Serilog.Core.Logger
-> 000001fb1339d5a8 Serilog.Core.Sinks.SafeAggregateSink
-> 000001fb1339d5c0 Serilog.Core.ILogEventSink[]
-> 000001fb1339af98 Serilog.Sinks.Http.Private.NonDurable.HttpSink
-> 000001fb1339b098 Serilog.Sinks.Http.Private.Time.PortableTimer
-> 000001fb1339b120 System.Threading.Timer
-> 000001fb1339b1f0 System.Threading.TimerHolder
-> 000001fb1339b140 System.Threading.TimerQueueTimer
...
300k x System.Threading.TimerQueueTimer
...
-> 000001f413bb8670 System.Threading.TimerQueueTimer
-> 000001f413bb8610 System.Threading.TimerCallback
-> 000001f413bb73e8 System.Runtime.Caching.CacheExpires
-> 000001f413bb7420 System.Runtime.Caching.ExpiresBucket[]
-> 000001f413bb7c98 System.Runtime.Caching.ExpiresBucket
Failed to enumerate GC references.
Failed to walk thread 25ec
It is legacy WebForms application, with Enterprise Library
blocks and with Unity
version 3.5. As logger is used Serilog
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论