MPM module configuration of apache server

Source: Internet
Author: User
Tags memory usage

The following content is for reference only and the MPM operations are not fully understood. This record is only for future use.
1. In the window, determine the working mode used by apache.
Run cmd in the apache Directory bin: httpd-l to check which modules are successfully loaded using httpd-M.
Use apachectl-l in linux

Prefork module: Process-based; worker module: thread-based;

2. Enable the MPM module configuration file

We need to enable the configuration file in the httpd. conf file, as shown below:
# Include conf/extra/httpd-mpm.conf (remove the annotator "#" before this line "#")
There is a configuration file named httpd-mpm.conf in the/conf/extra directory of the Apace installation directory. This file is mainly used for MPM module configuration. However, by default, the Apache MPM module configuration file is not enabled.

3. Modify the parameter configurations of the corresponding node based on the MPM module used by the Apache server. First, let's take a look at the default configuration in the mpm_winnt module:

Let's take a look at the default configuration in the mpm_winnt module:
# Because the mpm_winnt module only creates one sub-process, the parameter setting for a single sub-process is equivalent to the parameter setting for the entire Apache.

# ThreadLimit 350
ThreadsPerChild 150 # recommended settings: small website = 1000 medium website = 1000 ~ 2000 large websites = 2000 ~ 3500 set the average number of online users of the website
MaxRequestsPerChild 0 # recommended settings: small = 10000 medium or large = 20000 ~ 100000 set the maximum number of online users

The corresponding configuration parameters are used as follows:
ThreadsPerChild
The maximum number of concurrent threads for each sub-process.
MaxRequestsPerChild


The total number of requests that each sub-process can process. If the cumulative number of requests exceeds this value, the sub-process will end (and then determine whether to create a new sub-process as needed ), if the value is set to 0, the total number of requests is not Limited (the sub-process will never end ).
For mpm_winnt, the default value of ThreadLimit is 1920; for other mpM, the value is 64. Among them, ThreadLimit is the limit on the number of system threads. After modification, it will be directly seen in apache-status, that is, the maximum number of available threads (as shown below): 1 requests currently being processed, 349 idle workers
Note: Apache has a hard internal limit "ThreadLimit 20000" during compilation (for mpm_winnt, it is "ThreadLimit 15000"). You cannot go beyond this limit. ThreadsPerChlid is the number of sub-threads of the Apache process. This command sets the number of threads created by each sub-process. After these threads are created at startup, the child process will no longer create new threads. If you use an mpM that is similar to mpm_winnt and has only one sub-process, this value must be large enough to handle possible request peaks.
We recommend that you set this parameter to a non-zero value, which brings the following two benefits:
It can prevent potential memory leakage in the program and thus exhaust the memory.
A limited life cycle is provided for processes, which helps reduce the number of active processes when server load is reduced.
Note: In the above parameters that involve counting the number of requests, for KeepAlive connections, only the first request will be counted. The ServerLimi and ThreadLimit commands determine the number of active sub-processes and the number of threads in each sub-process. To change this hard limit, you must completely stop the server and then start the server (you cannot restart the server directly ).


Let's take a look at the default configurations of the mpm_worker K module and the mpm_worker module:
# Mpm_perfork module

StartServers 5 # recommended settings: small = default medium = 20 ~ 50-50 ~ 100
MinSpareServers 5 # recommended settings: consistent with StartServers
MaxSpareServers 10 # recommended settings: medium = 20 = 30 ~ 80-80 ~ 120
MaxClients 150 # recommended settings: small = 500 medium = 500 ~ 1500 large scale = 1500 ~ 3000
MaxRequestsPerChild 0 # recommended settings: small = 10000 medium or large = 10000 ~ 500000 (additionally, you need to set the ServerLimit parameter, which should be consistent with the value of MaxClients. )

# By default, the prefork configuration does not have the ServerLimit configuration. It is compiled in/usr/loca/apache2/bin/httpd (hexadecimal). Generally, the following error is reported:
MaxClients of 1000 exceeds ServerLimit value of 256 servers,
Lowering MaxClients to 256. To increase, please see the ServerLimit directive. # ServerLimit must be placed on MaxClients and the value> = MaxCliens
# Mpm_worker module

StartServers 2 # recommended settings: small = default medium = 3 ~ 5 to 5 ~ 10
MaxClients 150 # recommended settings: small = 500 medium = 500 ~ 1500 large scale = 1500 ~ 3000
MinSpareThreads 25 # recommended settings: small = medium = 50 ~ 100 large = 100 ~ 200
MaxSpareThreads 75 # recommended settings: small = medium = 80 ~ 160 large = 200 ~ 400
ThreadsPerChild 25 # recommended settings: small = medium by default = 50 ~ 100 large scale = 100 ~ 200
MaxRequestsPerChild 0 # recommended settings: small = 10000 medium or large = 10000 ~ 50000 (if MaxClients/ThreadsPerChild is greater than 16, you need to set the ServerLimit parameter. ServerLimit must be greater than or equal to the value of MaxClients/ThreadsPerChild .)

The corresponding configuration parameters are used as follows:
StartServers
The number of subprocesses created when Apache is started.
MinSpareServers
The minimum number of sub-processes in idle state.
Idle sub-processes are sub-processes that are not processing requests. If the number of idle sub-processes is less than MinSpareServers, Apache will generate a new sub-process at a maximum speed per second. This parameter must be adjusted only on very busy machines. This value should not be too large.
MaxSpareServers
The maximum number of idle sub-processes.
This parameter must be adjusted only on very busy machines. This value should not be too large. If you set the value of this command to a smaller value than MinSpareServers, Apache will automatically change it to MinSpareServers + 1.
MaxClients
The maximum number of requests that can be connected simultaneously.
Any request that exceeds the MaxClients limit will enter the waiting queue until the maximum value of the ListenBacklog command is reached.
For non-thread MPM (mpm_prefork), MaxClients indicates the maximum number of sub-processes that can be used to process client requests. The default value is 256. To increase this value, you must increase ServerLimit at the same time.
For a thread-type or hybrid MPM (mpm_beos or mpm_worker), MaxClients indicates the maximum number of threads that can be used to process client requests. The default value of the thread-type mpm_beos is 50. For hybrid MPM, the default value is 16 (ServerLimit) multiplied by 25 (ThreadsPerChild. Therefore, to increase MaxClients to more than 16 processes, you must increase the value of ServerLimit at the same time.
MinSpareThreads
The minimum number of idle threads.
Different MPM processes this command differently:
The default value of mpm_worker is 75. This MPM monitors the number of idle threads based on the entire server. If the total number of idle threads on the server is too small, the child process will generate a new idle thread. The default value of mpm_netware is 10. Since this MPM only runs a single sub-process, the MPM also monitors the number of idle threads based on the entire server. Mpm_beos and mpmt_os2 work in the same way as mpm_netware. The default value of mpm_beos is 1, and that of mpmt_os2 is 5.
MaxSpareThreads
The maximum number of idle threads.
Different MPM processes this command differently:
The default value of mpm_worker is 250. This MPM monitors the number of idle threads based on the entire server. If the total number of idle threads on the server is too large, the child process will kill the redundant idle threads. The default value of mpm_netware is 100. Since this MPM only runs a single sub-process, the MPM also monitors the number of idle threads based on the entire server. Mpm_beos and mpmt_os2 work in the same way as mpm_netware. The default value of mpm_beos is 50, and that of mpmt_os2 is 10.
END
Notes
ServerLimit indicates the maximum number of processes that Apache allows to create. It is worth noting that Apache has a hard limit of ServerLimit 20000 internally during compilation (for the mpm_prefork module, ServerLimit 200000 ). You cannot go beyond this limit. Be careful when using this command. If you set ServerLimit to a value that is much higher than actually needed, too much shared memory will be allocated. If ServerLimit and MaxClients are set to exceed the processing capability of the system, Apache may fail to start or the system may become unstable. Note: When configuring relevant parameters, ensure that the server has sufficient hardware performance (such as CPU and memory ). If it is found that, as the running time of the server increases, the memory usage of the server also increases, possibly due to memory leakage in the program, please adjust the value of the MaxRequestsPerChild parameter downward to reduce the impact of memory leakage, and then identify the problem in the program as soon as possible.

The following error message is displayed:

ServerTokens Full
ServerSignature On

Change
ServerTokens Prod
ServerSignature off

To be confirmed

Error. log contains a large number of output items: the network name specified by Sat Dec 24 17:21:28 2006] [warn] (OS 64) is no longer available. : Winnt_accept: Asynchronous AcceptEx failed .. The following is a solution. I tried it and it was OK. I tried it on multiple servers. If the AcceptEx problem occurs, it can be solved. The specific setting is as follows: 1. Remove the check box before LMhosts is enabled. 2. Select "control panel", "windows Firewall", "Advanced tab", "local connection settings", and "secure Web server (HTTPS)" in the service tab ). 3. Log out of Apache and start Apache again. At first, I did not quit. I restarted it directly. That is, I cannot. I must stop it before enabling it.

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.