1

问题:为什么会发生内存泄漏?是什么原因造成的?如何解决?

我有一台运行 1 个网站的服务器。它托管在 32 位应用程序池中。它在启动后会在内存中增长到 2-3 Gb。从这些 2-3 Gb 中,1-1.5 是我们托管代码的内存,我们正在处理它,但其他 1-1.5 Gb 是由 webengine4 模块分配的本机内存。我假设它是一些 IIS 模块(DebugDiag 1.2 的输出):

按分配大小排列的前 4 个函数

webengine4!W3_MGD_BUFFER_POOL::RentBuffer+1a  1,29 GBytes
webengine4!BUFFER::ReallocStorage+34  90.82 KBytes
webengine4!MemAlloc+24  63.45 KBytes
webengine4!MemAllocClear+24  400 Bytes

示例调用堆栈:

Function 
webengine4!W3_MGD_BUFFER_POOL::RentBuffer+1a 
webengine4!MgdGetBuffer+11 
System.Web.HttpResponseUnmanagedBufferElement..ctor() 
System.Web.HttpWriter.BufferData(Byte[], Int32, Int32, Boolean) 
System.Web.HttpWriter.WriteFromStream(Byte[], Int32, Int32) 
System.IO.Compression.DeflateStream.InternalWrite(Byte[], Int32, Int32, Boolean) 
System.IO.Compression.DeflateStream.Write(Byte[], Int32, Int32) 
System.IO.Compression.GZipStream.Write(Byte[], Int32, Int32) 
System.Web.HttpWriter.FilterIntegrated(Boolean, System.Web.Hosting.IIS7WorkerRequest) 
iiscore!`WWWServerTraceProvider::GetProviderGuid'::`2'::ProviderGuid 
DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr, Int32 ByRef, Boolean ByRef, Int32 ByRef) 
clr!InlinedCallFrame::`vftable' 
System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext, System.AsyncCallback) 
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest, System.Web.HttpContext) 
clr!InlinedCallFrame::`vftable' 
0x31E672 
0x31E672 
0x31E5CD 
System_Web_ni+1d1dac 
clr!FastNExportExceptHandler 
webengine4!__delayLoadHelper2+376 
iiscore!NOTIFICATION_CONTEXT::RequestDoWork+190 
iiscore!NOTIFICATION_CONTEXT::CallModulesInternal+305 
iiscore!NOTIFICATION_CONTEXT::CallModules+28 
iiscore!W3_CONTEXT::DoStateGeneralEvent+36 
iiscore!W3_CONTEXT::DoWork+c6 
iiscore!W3_MAIN_CONTEXT::ContinueNotificationLoop+1f 
iiscore!W3_MAIN_CONTEXT::ProcessIndicateCompletion+1f 
iiscore!W3_CONTEXT::IndicateCompletion+75 
webengine4!W3_MGD_HANDLER::IndicateCompletion+3d 
webengine4!MgdIndicateCompletion+24 
DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr, System.Web.RequestNotificationStatus ByRef) 
clr!InlinedCallFrame::`vftable' 
DomainNeutralILStubClass.IL_STUB_PInvoke(IntPtr, System.Web.RequestNotificationStatus ByRef) 
clr!InlinedCallFrame::`vftable' 
clr!ContextTransitionFrame::`vftable' 
0x31E5CD 
System_Web_ni+1d1dac 
clr!UM2MThunk_WrapperHelper+10 
clr!UM2MThunk_Wrapper+8c 
clr!Thread::DoADCallBack+f0 
clr!UM2MDoADCallBack+c0 
0x31E628 
clr!FastNExportExceptHandler 
clr! ?? ::FNODOBFM::`string'+26ffa 
clr!ThreadpoolMgr::WorkerThreadStart 
clr!SlowClrFlsSetValue+42 
clr! ?? ::FNODOBFM::`string'+41b4f 
clr!ThreadpoolMgr::WorkerThreadStart 
clr!ThreadpoolMgr::WorkerThreadStart 
clr!operator delete+41 
clr!ThreadpoolMgr::WorkerThreadStart 
clr! ?? ::FNODOBFM::`string'+41bd8 
clr!Thread::intermediateThreadProc+4b 
kernel32!BaseThreadInitThunk+e 
ntdll!__RtlUserThreadStart+70 
ntdll!_RtlUserThreadStart+1b 
clr!Thread::intermediateThreadProc 

我们也有这样的例外(但我认为,它们更简单,然后是原因):

    Exception type: OutOfMemoryException 
    Exception message: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Web.HttpResponseUnmanagedBufferElement.System.Web.IHttpResponseElement.GetBytes()
   at System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr)
   at System.Web.HttpResponse.FilterOutput()
   at System.Web.HttpApplication.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

我试过了,没有找到任何关于这个的信息。有人可以帮我吗?

4

1 回答 1

0

问题解决了。

我们确定 IIS 工作器由于数据急剧增长而承受着沉重的 CPU 和内存压力,因此 GC 没有足够的资源来完成它的工作。在我们进行真正的修复时,我可以向任何遇到类似解决方法的人建议:我们添加了额外的工作进程(我们的服务器是无状态的),它们在它们之间分配内存压力,因此 GC 可以工作并且非托管内存也消失了。

于 2013-07-23T17:05:40.867 回答