Discover and solve ASP. NET memory depletion (OOM) and "never restart" the server"

Source: Internet
Author: User
Tags mscorlib server hosting
Discover and solve ASP. NET memory depletion (OOM), and let the server "never restart"

Source: http://www.cnblogs.com/koumi/archive/2010/10/12/1849077.html

======== A pile of text below to illustrate one thing ---. NET Program, memory overflow, how to control. it mainly focuses on how to control and optimize HEAP size. to reduce the unexpected GC burden and the possibility of server hosting *.
It is unrealistic for large programs to fully rely on GC. for High-load servers, 80% of our stacks are often taken over by our own destructor, and assists with self-designed bufferpool to take over HEAP release to achieve HEAP controllable purpose, reduce sudden CPU load (CPU peak ). although it is not as controllable as C, it is more or less used to suppress the occurrence of OOM. Further development can completely avoid OOM ...... well, IF the performance and memory overhead have nothing to pursue THEN, you don't have to look at it ,,,,

ELSE

GO

==================================
1. Go to baidu and google the next windbg ..
2. the sos. dll framework comes with you, so you can only mention it for keyword search.
3. leakage,. net programs, mainly heap leakage. For large server programs, it is necessary to strictly troubleshoot OOM (Memory leakage) problems, saving GC overhead, memory overhead, cpu overhead, and improving support.
4. configure the environment variable to add the system Variable _ NT_DEBUGGER_EXTENSION_PATH C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727. This is to find sos. dll
5. Practice
Start windbg, open the debugging window, and load the sos. dll used for. NET debugging.
. Load sos
If there is no display after you press enter, It means there are no errors. You can run the debugging command at this time.
It must be noted that the windbg command comes with the header ,! The command for hitting the header is the sos. dll debugging command.

 

Command for displaying GC heap usage! Dumpheap-stat
The following figure shows the number of objects in the object table, memory usage of each object, and so on:
---------------------
0: 000>! Dumpheap-stat
Statistics:
MT Count TotalSize Class Name
7a787cc4 1 12 System. IO. FileSystemWatcher + FSWAsyncResult
7a75904c 1 12 System. Diagnostics. OrdinalCaseInsensitiveComparer
7a7575cc 1 12 System. CodeDom. Compiler. CodeDomConfigurationHandler
7a7571a8 1 12 System. Net. DefaultCertPolicy
7a75661c 1 12 System. Diagnostics. TraceListenerCollection
7a755834 1 12 System. Diagnostics. PerformanceCounterCategoryType
..................
68a66a88 227,559 12,743,304 System. Web. UI. WebControls. Literal
68a2f7fc 399,272 14,373,792 System. Web. UI. ControlCollection
68a92e2c 768,731 33,824,164 System. Web. UI. Control + OccasionalFields
68a884a0 641,952 38,517,120 System. Web. UI. LiteralControl
79124228 879,515 43,394,976 System. Object []
790fa3e0 1,431,594 122,806,484 System. String

 

 

Total 10,389,625 objects, Total size: 463,313,540
----------------------

 

 

1,431,594 System. String objects occupy 122 MBytes

 

 

Use! Dumpobj can view the composition of the System. String object

 

0: 000>! Dumpheap-type System. Web. UI. LiteralControl
Address MT Size Gen
023ea0a8 68a884a0 60 2 System. Web. UI. LiteralControl
023ea0e4 68a884a0 60 2 System. Web. UI. LiteralControl
023ea374 68a884a0 60 2 System. Web. UI. LiteralControl
023ea460 68a884a0 60 2 System. Web. UI. LiteralControl
023ea510 68a884a0 60 2 System. Web. UI. LiteralControl
023eab3c 68a884a0 60 2 System. Web. UI. LiteralControl
.......... CONTINUED ........
023fe31c 68a884a0 60 2 System. Web. UI. LiteralControl
023fe414 68a884a0 60 2 System. Web. UI. LiteralControl
023fe4c4 68a884a0 60 2 System. Web. UI. LiteralControl
023fe500 68a884a0 60 2 System. Web. UI. LiteralControl

 

Oh, it's basically LiteralControl.

 

Click the control address to analyze it! Do command

 

0: 000>! Do 023ea0a8
Name: System. Web. UI. LiteralControl
MethodTable: 68a884a0
EEClass: 68a88428
Size: 60 (0x3c) bytes
GC Generation: 2
(C: \ WINDOWS \ assembly \ GAC_32 \ System. Web \ 2.0.0.0 _ b03f5f7f11d50a3a \ System. Web. dll)
Fields:
MT Field Offset Type VT Attr Value Name
790fa3e0 4001fe0 4 System. String 0 instance 00000000 _ id
790fa3e0 4001fe1 8 System. String 0 instance 00000000 _ cachedUniqueID
68a2af44 4001fe2 c... em. Web. UI. Control 0 instance 023e8864 _ parent
68a91070 4001fe3 2c System. Int32 0 instance 0 _ controlState
68a85ea0 4001fe4 10... m. Web. UI. StateBag 0 instance 00000000 _ viewState
68a2af44 4001fe5 14... em. Web. UI. Control 0 instance 023e8864 _ namingContainer
68a273d0 4001fe6 18 System. Web. UI. Page 0 instance 01df4514 _ page
68a92e2c 4001fe7 1c... + OccasionalFields 0 instance 00000000 _ occasionalFields
68a2b378 4001fe8 20... I. TemplateControl 0 instance 00000000 _ templateControl
68a14528 4001fe9 24... m. Web. VirtualPath 0 instance 00000000 _ templateSourceVirtualDirectory
68a8bb48 4001fea 28... rs. ControlAdapter 0 instance 00000000 _ adapter
68a3a8f8 4001feb 30... SimpleBitVector32 1 instance 023ea0d8 flags
790f9c6 4001fda c70 System. Object 0 shared static EventDataBinding
> Domain: Value 000f0d00: NotInit 0011a720: 01df0028 <
790f9c6 4001fdb c74 System. Object 0 shared static EventInit
> Domain: Value 000f0d00: NotInit 0011a720: 01df0034 <
790f9c6 4001fdc c78 System. Object 0 shared static EventLoad
> Domain: Value 000f0d00: NotInit 0011a720: 01df0040 <
790f9c6 4001fdd c7c System. Object 0 shared static EventUnload
> Domain: Value 000f0d00: NotInit 0011a720: 01df004c <
790f9c6 4001fde c80 System. Object 0 shared static EventPreRender
> Domain: Value 000f0d00: NotInit 0011a720: 01df0058 <
790f9c6 4001fdf c84 System. Object 0 shared static EventDisposed
> Domain: Value 000f0d00: NotInit 0011a720: 01df0064 <
79124228 4001fec c88 System. Object [] 0 shared static automaticIDs
> Domain: Value 000f0d00: NotInit 0011a720: 01df0070 <
790fa3e0 4002211 34 System. String 0 instance 02238664 _ text

 

If a value is too large, you can continue to use it in depth! Do + address to go to view, in order to find the root cause of OOM... try

 

0: 000>! Do 1, 02238664
Name: System. String
MethodTable: 790fa3e0
EEClass: 790fa340
Size: 158 (0x9e) bytes
GC Generation: 2
(C: \ WINDOWS \ assembly \ GAC_32 \ mscorlib \ 2.0.0.0 _ b77a5c561934e089 \ mscorlib. dll)
String:
Fields:
MT Field Offset Type VT Attr Value Name
790fed1c 4000096 4 System. Int32 0 instance 71 m_arrayLength
790fed1c 4000097 8 System. Int32 0 instance 70 m_stringLength
790 fbefc 4000098 c System. Char 0 instance 3c m_firstChar
790fa3e0 4000099 10 System. String 0 shared static Empty
> Domain: Value 000f0d00: 790d6584 0011a720: 790d6584 <
79124670 400009a 14 System. Char [] 0 shared static WhitespaceChars
> Domain: Value 000f0d00: 01d413b8 0011a720: 01d44f80 <

 

We can see that the 32-bit address 02238664 is used for the end mark storage of the table.

 

Use! Objsize further command to view the object structure in the object, accurate to the class name, you can try it... there are also many commands to view the collection status of Gen. For unmanaged resources that haven't been released for a long time, you can also list them. At this time, you can do them to check the internal structure and find out which code segment it belongs, return your own. adjust the logic of the cs code .... in this case, the performance will be considerable. at the same time, you can try to use the CPU as much as possible, without having to sacrifice unnecessary CPU time on the framework and the underlying code glue layer .. always remember that the CPU time is user, not yours! In this way, if you know more about the memory, your program will be able to run faster and the persistent running time will be longer...

 

Generally, when the asp.net or socket server is running, the memory requirements are relatively high. If we cannot grasp the memory performance, it is really difficult to reproduce the environment to surpass the LAMP architecture.
In my opinion, memory can be saved, saved as much as possible, and used as efficiently as possible! So I wrote this post with a very superficial introduction. I wrote 20 minutes before and after, because I am going to bed...

 

---- [Chengdu] CCCP Soviet programmer

 

 

By the way, you can buy this "windows debugging technology" to see the http://bbs.dbgtech.net/forumdisplay.php? Fid = 16.

Welcome to the technical exchange group! QQ: 29123371
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.