Httpd.exe cpu usage 100% solution

Source: Internet
Author: User
Tags memory usage cpu usage

I said on the Internet that we have no limit on the number of apache concurrent operations and the number of sub-operations. Later, Baidu came up with the following code:

Edit httpd. conf

The code is as follows: Copy code

Win32DisableAcceptEx # add this line
ThreadsPerChild 250
MaxRequestsPerChild 0

Restart apache.

The MaxRequestsPerChild command sets the number of requests that an independent sub-process can process. After the "MaxRequestsPerChild number" request is processed, the child process will be terminated by the parent process. At this time, the memory occupied by the child process will be released. If there are other access requests, the parent process re-generates the child process for processing.

If MaxRequestsPerChild is set to 0 (unlimited) by default or a large number (such as more than 10000), each sub-process can process more requests, it will not reduce the access efficiency because of continuous termination or promoter processes, but if MaxRequestsPerChild is set to 0, if it occupies 200 ~ MB of memory, even if the load is down, the occupied memory will not be reduced. A server with a large memory can be set to 0 or a large number. Servers with small memory can be set to 30, 50, or 100 to prevent memory overflow.


Another solution

If you have no problem before, and suddenly there is a problem and the server has installed Kingsoft drug overlord, this may be because Kingsoft drug overlord or the upgrade Genie has modified WINSOCK.

Solution

Run the following command in Windows cmd:

The code is as follows: Copy code

Netsh winsock reset


There may also be a situation where there is no cpu point, the memory usage is very high, or suddenly it will be stuck for a while, this solution can try to add in httpd. conf

The code is as follows: Copy code

<IfModule mpm_winnt.c>
ThreadsPerChild 1000
MaxRequestsPerChild 10000
Win32DisableAcceptEx
</IfModule>

The above solution solves the non-fundamental problem. We can optimize apache, the most common one is apache cache optimization.

Apache cache is divided into two cache modes (mod_disk_cache and mod_mem_cache ):

Mod_disk_cache

A disk-based storage management module.

The hard disk file storage-based cache is implemented by the mod_disk_cache module:

The code is as follows: Copy code


<IfModule mod_cache.c> CacheDefaultExpire 3600
CacheMaxExpire 86400
CacheLastModifiedFactor 0.1
<IfModule mod_disk_cache.c>
CacheRoot/usr/local/apache/cache
CacheEnable disk/
CacheDirLevels 5
CacheDirLength 3
CacheMaxFileSize 10000000
CacheMinFileSize 1
</IfModule>
</IfModule>

Copy the preceding content to the httpd. con file of apache:

Search in the httpd. conf file

The code is as follows: Copy code

# LoadModule cache_module modules/mod_cache.so // remove the previous #

Use disk file cache:

The code is as follows: Copy code

# LoadModule disk_cache_module modules/mod_disk_cache.so // remove the previous #


Mod_mem_cache

A memory-based storage management module. Mod_mem_cache can be configured with two different operation modes: ① file descriptors opened by the cache; ② cached objects on the heap. Mod_mem_cache can be used to cache locally generated content or to cache the output content of the backend server in Reverse proxy mode.

The memory-based cache is mainly implemented by the mod_mem_cache module:

The code is as follows: Copy code


<IfModule mod_cache.c>

<IfModule mod_mem_cache.c>
CacheEnable mem/
MCacheSize 4096
MCacheMaxObjectCount 2000
MCacheMinObjectSize 1
MCacheMaxObjectSize 2048
</IfModule>
</IfModule>

 

After the installation is complete, search

The code is as follows: Copy code

LoadModule cache_module modules/mod_cache.so // remove the # above

Use the memory file cache:

The code is as follows: Copy code

# LoadModule mem_cache_module modules/mod_mem_cache.so // remove the previous #

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.