Guard against system. outofmemoryexception errors in ASP. NET caused by "Buffer Overflow Protection" of coffee ee

Source: Internet
Author: User

The system on the customer's server has been running stably for several years. After the customer changed the new server (dual-4-core CPU, 8 GB memory) for a while, it suddenly became unavailable, after you open the home page or log on successfully, system appears immediately. outofmemoryexception error. The system crashes completely.

After asking Gu Ge and Du Niang, the following conclusions are obtained:

 

On the ASP. NET web (u8soft. appserver) server, the memory used by ASP. NET is usually not equal to the total memory size. In the machine. in the config configuration file (directory), the configuration section contains the "memorylimit" attribute. The value of this attribute is a hundred points. The default value is "60", indicating that ASP is specified. net process (in the task manager, you can see ASP.. Net Process, aspnet_wp in iis5, w3wp in IIS6) can use 60% of all physical memory. When ASP. when the memory used by net exceeds this limit, IIS starts to automatically recycle (recycle) processes, that is, creating a new process to handle HTTP requests, the memory occupied by the old process is recycled. ?? When we have a server with a large memory, the value of "memorylimit" needs to be adjusted appropriately. For example, if we have a 4G memory server, 4G x 60% = 2.4g. However, for Win32 operating systems, a process occupies only 2 GB of memory space. When ASP. when the memory occupied by the net process starts to reach 2 GB, IIS does not start the recycle process because it does not reach the "reclaim threshold" of 2 GB. However, due to Win32 restrictions, in fact, this process cannot be allocated more memory, so outofmemoryexception may be thrown. To avoid such a situation, we must adjust "memorylimit" to make IIS process recycle earlier. ?? The ASP. NET process recommended by Microsoft occupies no more than 60% of the memory, and it is recommended that the calculated actual value not exceed 800 mb. That is to say, for a 4G memory server, it is best to set the "memorylimit" attribute to "20 ". Setting an appropriate collection threshold for IIS to recycle processes in a timely manner is very important to ensure the stable operation of the entire server and avoid outofmemoryexception. ?? In IIS6, the recovery threshold of ASP. NET processes is no longer determined by the "memorylimit" attribute in the configuration section, but by the settings in the application pool configuration in IIS manager. ?? However, even if these configurations are correctly configured, The outofmemoryexception cannot be completely avoided because of a variety of complicated causes, such as the memory collection operation may take too much time. Developers should note that they should always remember not to use or waste memory in the code.

 

According to this method, after several modifications, the configuration still has no effect, so it is further suspected that it is the ghost of various anti-virus software, especially the "Buffer Overflow Protection" of coffee ee ", the memory access is restricted, so the first one stops it. It is found that after the "Buffer Overflow Protection" of coffee EE is stopped, the system returns to normal. However, after dozens of seconds, the system crashed again. Why? Check the coffee again and find that "Buffer Overflow Protection" is automatically enabled ...... n methods were used to stop the service, and the customer service of the coffee for help was useless. The coffee could only be completely deleted from the server, so everything went back to normal.

We have recently studied this problem and found such technical materials:

 

 

On multiple processors (or multiple cores. net CLR garbage collection (GC) mechanism is run using server mode. In other words, that is, "Each CPU has a fixed GC memory space (HEAP )」, so if your GC memory space is 500 mb and you have 4 CPUs, it will take 2 GB of memory, system. outofmemoryexception exception!

To solve this problem, set GC to workstation mode, so that the entire master machine can share the same GC heap, to save your memory usage. To change GC to workstation mode, you must modify % WinDir % \ Microsoft. net \ framework \ v2.0.50727 \ ASPnet. config example (if it is. NET 1.1 to modify % WinDir % \ Microsoft. net \ framework \ v1.1.4322 \ ASPnet. config example ):

 

The default length of ASPnet. config is as follows:

 

 

<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<Runtime>
<Legacyunhandledexceptionpolicy enabled = "false"/>
<Legacyimpersonationpolicy enabled = "true"/>
<Alwaysflowimpersonationpolicy enabled = "false"/>
<Symbolreadingpolicy enabled = "1"/>
</Runtime>
</Configuration>

 

Add a line <gcserver enabled = "false"/> as follows:

 

 

 

<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<Runtime>
<Gcserver enabled = "false"/>
<Legacyunhandledexceptionpolicy enabled = "false"/>
<Legacyimpersonationpolicy enabled = "true"/>
<Alwaysflowimpersonationpolicy enabled = "false"/>
<Symbolreadingpolicy enabled = "1"/>
</Runtime>
</Configuration>

 

However, an out of Memory exception occurs in a 64-bit operating system, so if you use a 64-bit operating system (such as Windows Server 2003 64bit) you do not need to make such adjustments, but you still need enough memory. Otherwise, too many paging shards will reduce your asp. net!

In addition to this, ASP. NET applications in the production environment must Disable debug and trace set during development in Web. config so that the memory will not cause extra burden. When ASP. NET applications enable the debug mode, all symbol files (*. PDB) are loaded into the memory, which not only consumes a lot of memory, but also reduces the execution efficiency.

 

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.