http://tech.ccidnet.com/pub/Article/c737_a47607_p1.html
Apache 2.0 Performance Optimization Author: ◇ issued Zhenguang Qi Xing flying time: 2003.05.27
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 = mpmchoose 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 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 check the default httpd.conf profile, which contains the following configuration segment:
#define default_thread_limit 64 # define max_thread_limit 20000 These two rows correspond to the limit of ThreadPerchild and Threadlimit. It is best to change 64 to the desired value before configure. Note that do not set these two values too high, exceeding the system's processing power, so that the system is very unstable due to Apache. The total number of requests that can be handled at the same time in Worker mode is determined by the total number of sub-process by threadsperchild values, which should be greater than equal to MaxClients. If the load is large, the existing child process cannot meet, the control process will derive a new child process. The default maximum child process is 16, and it is also necessary to explicitly declare the ServerLimit when it is increased. The maximum 20000). These two values are located in the source code tree server / mpm / worker / worker.c: #define default_server_limit 16 # define max_server_limit 20000 Need to note, if it explicitly declares ServerLimit, then it must be multiplied by ThreadsperChild It is equal to MaxClients, and MaxClients must be an integer multiple of ThreadsperChild, otherwise Apache will automatically adjust to a corresponding value (probably a non-desired value). Below is the author's Worker configuration segment: