简体   繁体   中英

How to write memory usage log in ASP.NET

We got "out of memory" issue on production servers. What API can we use to get live memory (physical and managed) usage of the ASP.NET application?

Thanks.

PS: we're forbidden to profile memory with tools.

Also an Out of memory doesn't necessarily mean what you think. heavy memory fragmentation due to excessive object creation can be reported as out of memory since the GC is not able to find a continuous block of memory large enough for next (or last attempted) allocation.

.Net performance counters can help you with a number of managed memory related stats.

This page details some of the ones available- http://msdn.microsoft.com/en-us/library/x2tyfybc.aspx

You can use normal windows memory counters to get an overview of non-managed memory- http://msdn.microsoft.com/en-us/library/aa965225(VS.85).aspx

Well, the first thing that I can suggest you is to take a memory dump when your w3wp.exe usage is high. You should takes these dumps and analyze it yourself, or get an expert to do it.

http://blogs.msdn.com/tess will tell you how if you are interested in doing it.

BUT... before you do any of the real exercise... two things that you absolutely must do.

  1. Turn Debug = False in all your web.config files http://aspalliance.com/1341

  2. Turn Trace = False in all your web.config files since the trace data is maintained in your memory and worsens memory shortage.

in addition to the performance counters you could use the profiling tools shipped with Visual Studio in order to monitor the memory usage. This step can help you on identifing memory issues before the code is released to production. Here's how to do it with VS2010: http://msdn.microsoft.com/en-us/library/dd264934.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM