Apache (ii)

Source: Internet
Author: User
Tags http authentication

Three types of MPM and configuration of Apache

First, MPM is Multi-Processing Modules, which represents the multi-processing module in Apache, and currently includes three modes in Apache 2.2/2.4 on Linux: Prefork, worker, and event mode.

1.worker

A worker is a multi-process multithreaded model in which a process has multiple threads, and each thread processes a connection. Worker mode saves system memory resources more than prefork. However, you need to be aware of the compatibility of program modules such as Apache and PHP in worker mode.

Configuration: Only need to add--with-mpm=worker when installing compile.

After the installation is complete, open the configuration file for MPM/usr/local/apache/conf/extra/httpd-mpm.conf

<ifmodule mpm_worker_module>30</ Ifmodule>

# startservers: Number of service initial processes

# Minsparethreads: Minimum number of idle threads

# Maxsparethreads: Maximum number of idle threads

# threadsperchild: Number of fixed threads per child process

# Maxrequestworkers: Maximum number of worker threads

# Maxconnectionsperchild: One server process service with maximum number of connections

The Worker generates a "startservers" sub-process by the master control process, each of which contains a fixed number of threadsperchild threads, and each thread processes the request independently. Again, in order not to generate a thread when the request arrives

minsparethreads and maxsparethreads set the minimum and maximum number of idle threads, and the maximum default values for Minsparethreads and Maxsparethreads are 75 and 250, respectively. These two parameters have little effect on Apache performance, and can be adjusted according to the actual situation.

maxrequestworkers Sets the maximum total number of clients that are simultaneously connected. If the total number of threads in an existing child process does not meet the load, the control process will derive the new child process

Threadsperchild is the most performance-related instruction in the worker mpm. The maximum default value for Threadsperchild is 64, and 64 is not enough if the load is large. At this point to explicitly use the THREADLIMIT directive, its maximum default value is 20000, can be modified in source code,/HOME/APACHE/SERVER/MPM/WORKER/WORKER.C.

The total number of requests that can be processed concurrently in worker mode is determined by multiplying the total number of child processes by the Threadsperchild value, which should be greater than or equal to maxrequestworkers. If the load is large and the number of existing child processes is not met, the control process derives the new child process. The default maximum number of child processes is 16, the increase also requires an explicit declaration of serverlimit (the maximum value is 20000, can be modified in source code,/HOME/APACHE/SERVER/MPM/WORKER/WORKER.C). It is important to note that if Serverlimit is explicitly declared, then it must be multiplied by the value of threadsperchild to be greater than or equal to maxrequestworkers. And maxrequestworkers must be an integer multiple of threadsperchild, otherwise Apache will automatically adjust to a corresponding value.

Actual Application Data:

<ifmodule worker.c>3200

2.prefork

There is no thread in the Prefork concept, is a multi-process model, a process to process a connection, stable, fast response. The disadvantage is that it consumes memory very much when the number of connections is large.

Configuration: Only need to add--with-mpm=prefork when installing compile.

After the installation is complete, open the configuration file for MPM/usr/local/apache/conf/extra/httpd-mpm.conf

<ifmodule mpm_prefork_module>startservers 5minspareservers 5maxspareservers  Maxrequestworkersmaxconnectionsperchild 0</ifmodule>    

# startservers: Number of child processes initially established

# Minspareservers: The minimum value of the automatically created process

# Maxspareservers: Maximum number of idle processes

# Maxrequestworkers:apache can handle requests at the same time (most important)-that is, the number of concurrent connections!! (Prior to apache2.3.13 version maxrequestworkers is known as maxclients)

# Maxconnectionsperchild: Maximum number of connections per child process

Prefork control process After initially establishing the "startservers" sub-process, in order to meet the needs of minspareservers settings, create a process, wait a second, continue to create two, and then wait a second, Continue to create four ... This increases the number of processes created by the number of digits, up to 32 per second, until the value of the Minspareservers setting is met. This pattern eliminates the need to generate new processes when the request arrives, reducing overhead to increase performance.

maxspareservers Sets the maximum number of idle processes, and if the number of idle processes is greater than this value, Apache will automatically kill some of the unwanted processes. This value should not be set too large, but if you set a value smaller than minspareservers, Apache will automatically adjust it to minspareservers+1. If the site load is large, consider increasing minspareservers and maxspareservers at the same time.

Maxconnectionsperchild Sets the number of requests that can be processed by each child process. Each child process is automatically destroyed after it has processed "maxconnectionsperchild" requests. 0 means infinity, that is, the child process never destroys. Although the default setting of 0 enables each subprocess to process more requests, there are two important benefits if set to a value other than 0:

    • To prevent accidental memory leaks.
    • The number of child processes is automatically reduced when the server load drops.

Therefore, this value can be adjusted according to the load of the server. (usually considered 10000 or so appropriate)

Maxrequestworkers is one of the most important of these directives, setting the request that Apache can process at the same time, which is the most influential parameter to Apache performance. If the total number of requests has reached this value (which can be confirmed by Ps-ef|grep Http|wc-l), then the subsequent request will be queued until a processed request has been completed. This is the main reason why the system resources are still a lot left and HTTP access is slow. Although theoretically the larger the value, the more requests can be processed, but the Apache default limit cannot be greater than 256. If you set this value to greater than 256, then Apache will not be able to start. In fact, 256 is not enough for sites with slightly heavier loads. In Apache 1.3, this is a hard limit. If you want to increase this value, you must find the "#define HARD_SERVER_LIMIT 256" line by looking for 256 in the src/include/httpd.h in the source tree under manual modification before "configure". Change 256 to the value you want to increase (such as 4000), and then recompile Apache. The new serverlimit directive was added to Apache 2.0, making it possible to increase maxrequestworkers without recompiling Apache. As shown below:

<ifmodule mpm_prefork_module>10000 </IfModule>

In the above configuration, the maximum value of Serverlimit is 20000, which is sufficient for most sites. If you want to increase this value, you must be in the source code directory
The following two lines in the/HOME/APACHE/SERVER/MPM/PREFORK/PREFORK.C can be modified accordingly:
#define DEFAULT_SERVER_LIMIT 256
#define MAX_SERVER_LIMIT 20000

3.event

The event is a variant of the worker pattern that separates the service process from the connection and can withstand higher concurrent loads when the keepalive is turned on. The event mode does not support HTTPS access (HTTP authentication related issues) very well.

Configuration: My Linux environment uses CentOS 7, compile and install without--WITH-MPM parameters, default is the event mode. Other systems may need to add--with-mpm=event

After the installation is complete, open the configuration file for MPM/usr/local/apache/conf/extra/httpd-mpm.conf

<ifmodule mpm_event_module>30</ Ifmodule>

# startservers: Number of service initial processes

# Minsparethreads: Minimum number of idle threads

# Maxsparethreads: Maximum number of idle threads

# threadsperchild: Number of fixed threads per child process

# Maxrequestworkers: Maximum number of worker threads

# Maxconnectionsperchild: One server process service with maximum number of connections

As with worker mode

Reference Document Source: http://www.cnblogs.com/fnng/archive/2012/11/20/2779977.html

Apache (ii)

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.