Article Title: Apache: the introduction of MPM improves performance. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The performance improvement of Apache 2.0 is the most attractive. On Unix systems that support POSIX Threads, Apache can use different MPM to run in a mix of multi-process and multi-thread modes to enhance the scalability of some configurations. Compared with Apache 1.3, version 2.0 has made a lot of Optimizations to improve processing capabilities and scalability, and most of the improvements will take effect by default. However, at the time of compilation and running, 2.0 also has many options that can significantly improve the performance. This article does not want to describe commands that exchange functions for speed, such as HostnameLookups, but only describes the core features that affect performance in 2.0: MPM (Multi-Processing Modules, Multi-channel Processing module) basic working principle and configuration instructions.
It is no exaggeration to say that the introduction of MPM is the most important change in Apache 2.0. As you know, Apache is based on modular design, while Apache 2.0 extends the most basic functions of modular design to Web servers. The server is loaded with a multi-channel processing module, which is responsible for binding the network port of the Local Machine, accepting requests, and scheduling sub-processes to process requests. Extended modular design has two important benefits:
◆ Apache supports multiple operating systems in a more concise and effective manner;
◆ Servers can be customized according to the special needs of the site.
At the user level, MPM looks very similar to other Apache modules. The main difference is that only one MPM can be loaded to the server at any time.
Specifies the MPM method.
The following describes how to specify MPM in Apache 2.0 based on Red Hat Linux 9 (Apache uses 2.0.45 ). First decompress the source code package httpd-2.0.45.tar.gz, generate the httpd-2.0.45 directory (Apache 1.3source code package naming rules are apache_1.3.nn.tar.gz, and 2.0version is httpd-2.0.nn.tar.gz, where NN is the version number ).
Go to the httpd-2.0.45 directory and run the following code:
$./Configure -- help | grep mpm
Display: -- with-mpm = MPMChoose the process model for Apache to use. MPM = {beos | worker | prefork | mpmt_os2 | perchild | leader | threadpool}
The preceding operation is used to select the MPM module of the process model to be used. Beos and mpmt_os2 are the default MPM on BeOS and OS/2 respectively. perchild is designed to run different sub-processes with different user and group identities. This is especially useful when running multiple virtual hosts that require CGI, and it is better than the SuExec mechanism in version 1.3. The leader and threadpool are both worker-based variants and are still in the experimental stage. In some cases, they do not work as expected. Therefore, Apache is not officially recommended. Therefore, we will focus on prefork and worker, the two products with the greatest performance relationship MPM (for other MPM details, see Apache official documentation: http://httpd.apache.org/docs-2.0/mod ).
Working Principle and configuration of prefork
If "-- with-mpm" is not used to explicitly specify an MPM, prefork is the default MPM on Unix platforms. It adopts the pre-school child process mode, which is also used in Apache 1.3. Prefork itself does not use threads. Version 2.0 uses it to maintain compatibility with version 1.3. On the other hand, prefork uses a separate sub-process to process different requests, processes are independent from each other, which makes them one of the most stable MPM.
If prefork is used, after make compilation and make install, "httpd-l" is used to determine the currently used MPM. c (if you see worker. c indicates that worker MPM is used, and so on ). Check the default httpd. conf configuration file, which contains the following configuration sections:
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
The working principle of prefork is that after the control process initially creates a "StartServers" sub-process, it creates a process to meet the needs of the MinSpareServers settings, waits for one second, creates two more, and then waits for one second, create four more ...... In this way, the number of Created processes is increased exponentially, up to 32 processes per second until the value set by MinSpareServers is met. This is the origin of prefork. This mode eliminates the need to generate new processes when requests arrive, thus reducing system overhead and increasing performance.
MaxSpareServers sets the maximum number of idle processes. If the number of idle processes is greater than this value, Apache automatically kill unnecessary processes. This value should not be too large, but if it is 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.
MaxRequestsPerChild sets the number of requests that each sub-process can process. Each sub-process is automatically destroyed after processing "MaxRequestsPerChild" requests. 0 means that the sub-process will never be destroyed. Although the default value is 0, each sub-process can process more requests, setting it to a non-zero value also has two important advantages:
◆ Prevents accidental Memory leakage;
◆ When the server load drops, the number of sub-processes is automatically reduced.
Therefore, you can adjust this value based on the server load. I think about 10000 is suitable.
[1] [2] Next page