The difference and configuration switch of Apache two working modes

Source: Internet
Author: User

1 , Redhat Linux View below Apache Version number

Under Apache installation directory bin, use the following command to view it.

Use command:./httpd-v

Example:

2 , view Apache Current mode of work

Apache has prefork and worker working mode

Use command:./apachectl–l

Example:

From the above results know that at that time httpd work in the prefork mode.

When configure, you can set the working mode to either worker mode or Prefork mode by specifying parameters.

Use command:./configure–with-mpm=worker

Example: set to worker mode

Apache the two modes of service are detailed:

Http://www.cnblogs.com/ghj1976/archive/2011/01/11/1932764.html

prefork the working principle and configuration
If you do not explicitly specify some kind of mpm,prefork without "--WITH-MPM", the default MPM on the UNIX platform. The pre-derivation process is also the pattern used in Apache 1.3. Prefork itself is not used to thread, version 2.0 uses it to maintain compatibility with version 1.3, on the other hand, prefork separate processes to handle different requests, and the process is independent of each other, making it one of the most stable mpm.

If you use Prefork, when you use "httpd-l" to determine which MPM is currently in use after make compilation and makes install installation, you should see PREFORK.C (if you see the worker.c description using worker MPM, and so on). Then look at the default generated httpd.conf configuration file, which contains the following configuration segments:

<ifmodule prefork.c>

Startservers 5

Minspareservers 5

Maxspareservers 10

MaxClients 150

Maxrequestsperchild 0

</IfModule>

Prefork's work is that the control process creates a process, waits a second, continues to create two, waits a second, continues to create four, after the "startservers" child process was initially established to meet the minspareservers settings. This increases the number of processes created, up to 32 per second, until the value of the Minspareservers setting is met. This is the origin of the pre-derivation (prefork). This pattern can reduce system overhead to increase performance by eliminating the need to generate new processes when requests arrive.

Maxspareservers sets the maximum number of idle processes, and if the number of idle processes is greater than this value, Apache automatically kill some redundant processes. This value should not be set too large, but if the value set is smaller than Minspareservers, Apache will automatically adjust it to minspareservers+1. If the site load is large, consider increasing both minspareservers and maxspareservers.

Maxrequestsperchild sets the number of requests that each child process can handle. Each subprocess is automatically destroyed after processing the "Maxrequestsperchild" request. 0 means infinite, that is, the child process never destroys. Although the default setting of 0 allows each subprocess to handle more requests, it has two important benefits if set to a value other than 0:

To prevent accidental memory leaks;

The number of child processes is reduced automatically when the server load drops.

Therefore, you can adjust this value based on the server's load. Personally think about 10000 more appropriate.

MaxClients is one of the most important of these directives, setting the request that Apache can handle at the same time, which is the most influential parameter to Apache performance. The default value of 150 is far from sufficient, and 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 that there are a lot of system resources left and the HTTP access is slow. The system administrator can dynamically adjust this value based on hardware configuration and load conditions. Although theoretically the larger the value, the more requests can be processed, but the Apache default limit is not greater than 256. If you set this value to greater than 256, then Apache will not start. In fact, 256 is not enough for a site with a heavier load. In Apache 1.3, this is a hard limit. If you want to increase this value, you have to "configure" before the manual modification of the source code tree in the Src/include/httpd.h to find 256, you will find the "#define HARD_SERVER_LIMIT 256" this line. Change 256 to the value you want to increase (for example, 4000), and then recompile Apache. The new serverlimit directive was added to Apache 2.0, making it possible to increase maxclients without recompiling Apache. The following is the Prefork configuration segment:

<ifmodule prefork.c>

Startservers 10

Minspareservers 10

Maxspareservers 15

Serverlimit 2000

MaxClients 1000

Maxrequestsperchild 10000

</IfModule>

In the above configuration, the maximum value of Serverlimit is 2000, which is sufficient for most sites. If you want to increase this value again, the following two lines in the server/mpm/prefork/prefork.c under the source tree are modified accordingly:

#define DEFAULT_SERVER_LIMIT 256

#define MAX_SERVER_LIMIT 2000

worker the working principle and configuration

Relative to Prefork,worker is a new MPM in version 2.0 that supports multi-threaded and multi-process hybrid models. Because of the use of threads, a relatively large amount of requests can be processed, and system resources are less expensive than a server-based server. However, workers also use multiple processes, and each process generates multiple threads to gain stability based on the process server. This mpm way of working will be the development trend of Apache 2.0.

After the Configure-with-mpm=worker, make build, made install installation. The following configuration segments are available in the default generated httpd.conf:

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.