[Reserved] This is an article I have written before, and there must be, the main content is from the official document. Talking about Apache, most system administrators are very impressed with their stable version 1.3. Although Apache 2.0 has long developed from Alpha, Beta to the current GA (General Availability), some people think that development is not available to the stable version of the production environment. In particular, the version 1.3 version of the API is not compatible with version 2.0, making a large number of modules must be rewritten to use it on version 2.0. The internal change between Apache 1.3 and 2.0 is indeed, with Apache founder Brian Behlendorf's own words: "This version includes hundreds of new features, so this product should have a product number such as 3.1 or 8i, and Not 2.0. "Apache 2.0 joins a lot of core improvements and new features, such as UNIX threads, multi-protocol support, new build systems, better support for non-Unix platforms, IPv6 support, new Apache API, filter, Multi-language error response, native Windows NT Unicode support, simpler configuration, and upgrade regular expression library, etc. Of course, it also includes important improvements to many modules, and has also joined some new modules. In order to make Apache to upgrade from version 2.3 to version 2.0, the Apache development team has done a lot of work. Many important modules are now able to support version 2.0, such as PHP, Fastcgi, MOD_PERL, MOD_PYTHON, etc. On HTTPD.conf instruction configuration syntax, the current version 2.0.45) and version 1.3 have been pretty good. For example, for the previous version 2.0, if you want to use PHP, it is generally implemented with a filter; the current version of the LoadModule statement in version 1.3 is used as a recommended way to load PHP in the PHP official document. As long as you understand the new features of Apache 2.0, upgrade from version 1.3 to version 2.0 will be a very easy thing. Using Apache 2.0 is a general trend, because Apache's development team has transferred the development center to version 2.0. The 1.3 version has been released from 1.3.27 since October 2002, and the 2.0 version was released in January this year after 2.0.43 in January this year after 2.0.43 in January this year. 2.0.45 and contain many improvements and corrections. The introduction of MPM brings performance to improve Apache 2.0 in performance. Improvement. On UNIX systems that support POSIX threads, Apache can run in a multi-process and multi-threaded phase mixed mode, enhanced the expandable performance of the partial configuration with a different MPM. A large amount of optimization is made compared to the Apache 1.3, 2.0, and most improvements can take effect in the default state. But in compilation and running, there are many options that can significantly improve performance. This article does not want to describe those instructions such as Hostnamelookups, etc., but only explain the core characteristics of the surfactity in 2.0: the basic working principle and configuration instructions of MPM (Multi-Processing Modules, Multiple Division). Not exaggerated, the introduction of MPM is the most important change in Apache 2.0. Everyone knows that Apache is based on modular design, and Apache 2.0 has expanded 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 native network port, accepting requests, and dispatching processes to handle requests. There are two important benefits of extending modular design: ◆ Apache can be more concise and effectively support multiple operating systems; ◆ Server can customize the special needs of the site.
At user-level, MPM looks very similar to other Apache modules. The main difference is that only one MPM can be loaded into the server at any time. Method for specifying MPM The following is a platform with Red Hat Linux 9, which shows how to specify MPM in Apache 2.0 (Apache is 2.0.45). First decompress the source code package httpd-2.0.45.tar.gz, generate httpd-2.0.45 directory (Apache 1.3 source code package naming rules are apache_1.3.nn.tar.gz, and version 2.0 is httpd- 2.0.nn.tar.gz, where NN is the secondary version number). Enter the HTTPD-2.0.45 directory, run the following code: $ ./configure --help | GREP MPM is shown below: --with-mpm = mpm choose the process model for apache to use. Mpm = {beos | worker | prefork | MPMT_OS2 | Perchild | Leader | ThreadPool} The above operation is used to select the process model to use, which is the MPM module. BEOS, MPMT_OS2 is the default MPM, which is the default MPM, and OS / 2, respectively. The primary design of Perchild is to run different sub-processs with different users and groups. This is especially useful when running multiple virtual hosts that require CGI, making it better than the SUEXEC mechanism in version 1.3. LEADER and THREADPOOL are all based on Worker, but also in experimental phases. In some cases, it does not work as expected, so Apache official is not recommended. Therefore, we mainly describe the two-kind and performance relationship of Prefork and Worker (for details on other MPMs, see Apache official document: http://httpd.apache.org/docs-2.0/mod/) . PREFORK Working principle and configuration If you do not need "--with-MPM" explicitly specify some MPM, Prefork is the default MPM on the UNIX platform. The pre-paused child process it use is also the model used in Apache 1.3. Prefork itself does not use threads, version 2.0 is used to maintain compatibility with version 1.3; on the other hand, PREFORK has handled different requests with separate child processes, and between the processes are independent of each other, which makes it become One of the most stable MPMs. If you use Prefork, after Make Compilation and Make Install installation, use "httpd -l" to determine the current Used MPM, you should see prefork.c (if you see Worker MPM, you can push ). Then, the default generated httpd.conf configuration file contains the following configuration segment:
This mode can not have to generate new processes when requested, thereby reducing system overhead to increase performance. MaxSpareServers set the maximum number of idle processes, if the number of idle processes is greater than this value, Apache will automatically kill some extra processes. This value does not set too much, but if the value set is smaller than the MinsPareServers, Apache will automatically adjust to minSpareServers 1. If the site load is large, consider increasing MinSpareServers and MaxSpareServers. MaxRequestSperChild Sets the number of requests that can be handab to each child process. Each child process will be automatically destroyed after processing the "maxRequestsperchild" request. 0 means infinity, that is, the child process will never be destroyed. Although the default set is 0 to handle more requests, if there is a non-zero value, there are two important benefits: ◆ Prevent unexpected memory leaks; ◆ When the server load has dropped, the other will be automatically reduced The number of child processes. Therefore, this value can be adjusted according to the load of the server. The author believes that 10,000 is relatively appropriate. MaxClients is the most important one in these instructions, setting Apache's request at the same time, is the maximum influence on Apache performance. Its default 150 is far less than enough. If the total number of requests has reached this value (can be confirmed by PS-EF | GREP HTTP | WC -L), then the following request is to queue until a certain request is completed. . This is the main reason why the system resources remain a lot and HTTP access is slow. System administrators can dynamically adjust this value based on hardware configuration and load conditions. Although this value is theoretically, the more requests can be handled, but the Apache default restriction cannot be greater than 256. If this value is set to be greater than 256, then Apache will not be able to start. In fact, 256 is not enough for the site for load. In Apache 1.3, this is a hard limit. If you want to increase this value, you must find 256 in the SRC / Include / httpd.h of the source code tree in front of "configure", will find the "#define hard_server_limit 256". Change 256 to an increase value (such as 4000), then recompile Apache. The ServerLimit directive is added to Apache 2.0 so that you can increase MaxClients without compiling Apache. Below is the author's prefork.c> StartServers 10 MINSPARSERVERS 10 MAXSPARSERVERVERS 15 ServerLimit 2000 MaxClients 1000 maxRequestSperChild 10000 ifmodule> The maximum value of ServerLimit is 20000, which is enough for most sites. If you must increase this value, you can modify the following two rows in Server / MPM / Prefork / Prefork.c under the source tree: #define default_server_limit 256 #define max_server_limit 2000 Worker works and configuration relative Prefork, Worker is a new version of MPM that supports multi-threaded and multi-process mixed models in version 2.0. Since the thread is used, the relative massive request can be handled, and the overhead of the system resource is less than the process-based server. However, Worker also uses a multi-process, each process generating multiple threads to obtain the stability of the process server. This MPM's way to work will be the development trend of Apache 2.0.
After configure -with-mpm = worker, Make Compilation, Make Install installation. The following default configuration section in httpd.conf generated: