MPM-Apache Working Mode

Source: Internet
Author: User

MPM -- Apache Working Mode
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. MPM (Multi-processing modules, multi-channel processing module) is the core feature that affects performance in apache2.0. 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. The following example shows how
How to specify MPM in 2.0. # Tar-xvzf httpd-2.0.59.tar.gz # cd httpd-2.0.59 #. /configure -- help | grep MPM -- 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, that is, the MPM module. BEOs and mpmt_os2 are
The default MPM on BEOs and OS/2. perchild is designed to run different sub-processes as different users and groups. 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 mainly describe the product-level MPM with the highest performance relationship between prefork and worker. 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. The pre-Dispatch process method adopted by Apache 1.3 is also used. 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. After prefork, make, and make install are used, use "httpd-L" to determine
MPM, you should see prefork. C (if you see worker. C, it indicates that worker MPM is used, and so on ). Then, check the httpd generated by the missing province. conf configuration file, which contains the following configuration segments: startservers 5 minspareservers 5 maxspareservers 10 maxclients 150 maxrequestsperchild 0 prefork, after the "startservers" sub-processes are created at the beginning
If the minspareservers setting is full, you need to create a process. Wait for one second to create two more processes. Wait for another second to create four more processes ...... 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 the request arrives, 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 change it to minspareservers + 1. If the site load is large, consider increasing minspareservers and maxspareservers at the same time. Maxrequestsperchild sets the request count that can be handled by each sub-process. Each sub-process
After a "maxrequestsperchild" request is processed, it is automatically destroyed. 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: # It can prevent 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. Maxclients is the most important of these commands. It is not enough to set the default value of 150 for requests that can be processed by Apache simultaneously. If the total number of requests reaches this value
(Parameters with the greatest impact on Apache performance. , The subsequent requests will be queued until a processed request is completed. Through PS-Ef | grep HTTP | WC-l) This is the main reason why there are still a lot of system resources and HTTP access is slow. The system administrator can dynamically adjust the value based on hardware configuration and load conditions. In theory, the larger the value, the more requests can be processed. Apache cannot exceed 256 by default. If you set this value to greater than 256, Apache cannot start. In fact, 256 is not enough for sites with a slightly higher load. In Apache 1.3
This is a hard limitation. To increase this value, you must search for 256 in src/include/httpd. h under the source code tree manually modified before "Configure", and you will find the line "# define hard_server_limit 256. Change 256 to the value to be increased (for example, 4000), and re-compile Apache. Added the serverlimit command in Apache 2.0 to increase maxclients without re-compiling Apache. The following is the author's prefork configuration section: startservers 10
Minspareservers 10 maxspareservers 15 serverlimit 2000 maxclients 1000 maxrequestsperchild 10000 in the preceding configuration, the maximum serverlimit value is 2000, which is sufficient for most sites. If you need to increase the value, modify the following two lines in server/MPM/prefork. C under the source code tree: # define default_server_limit 256 # define max_server_limit
20000
Compared with prefork, worker is a brand new MPM that supports multi-thread and multi-process hybrid models in version 2.0. Because
So it can process a relatively large number of requests, and the overhead of system resources is smaller than the process-based server. However, worker also uses multiple processes, and each process generates multiple threads to obtain the stability of the process server. This kind of MPM will be the trend of Apache 2.0. After configure-with-MPM = worker, make and install it. The default httpd. conf configuration section is startservers 2 maxclients 150 minsparethreads 25.
The working principle of maxsparethreads 75 threadsperchild 25 maxrequestsperchild 0 worker is that a "startservers" sub-process is generated by the main control process, and each sub-process contains a fixed number of threadsperchild threads, each thread processes Requests independently. Similarly, in order not to generate a thread when the request arrives, minsparethreads and maxsparethreads have set the minimum and maximum number of Idle threads. maxclients sets that if the total number of threads in the existing sub-processes cannot meet the load, control Process will be derived
Total number of threads in all sub-processes. A new sub-process. The maximum default values of minsparethreads and maxsparethreads are 75 and 250, respectively. These two parameters have little impact on Apache performance and can be adjusted as needed. Threadsperchild is the most performance-related command in worker MPM. The maximum default value of threadsperchild is 64. If the load is large, 64 is not enough. The maximum default value of the threadlimit command is 20000. The preceding two values are located in the source code tree server/MPM/worker. C.
The following two rows: # define default_thread_limit 64 # define max_thread_limit 20000 correspond to the number of restrictions of threadsperchild and threadlimit. It is best to change 64 to the desired value before configure. Note: Do not set these two values too high to exceed the processing capability of the system. As a result, the system is unstable because Apache cannot be moved. In worker mode, the total number of requests that can be processed simultaneously is determined by the total number of sub-processes multiplied by the value of threadsperchild. The value must be greater than or equal to maxclients. If the load is large and the number of existing sub-processes cannot meet the requirements, the control process will derive a new
Sub-process. By default, the maximum number of sub-processes is 16. When you increase the number, you must explicitly declare serverlimit (the maximum value is 20000 ). These two values are located in the following two lines in the source code tree server/MPM/worker. C: # define default_server_limit 16 # define max_server_limit 20000
Note that if serverlimit is explicitly declared, the value multiplied by threadsperchild must be greater
In maxclients, and maxclients must be an integer multiple of threadsperchild; otherwise, Apache will automatically tune the section to a corresponding value (possibly an unexpected value ). The following is the author's worker configuration section: startservers 3 maxclients 2000 serverlimit 25 minsparethreads 50 maxsparethreads 200 threadlimit 200 threadsperchild 100 maxrequestsperchild 0,
You can understand the working principles of the two important mpm, prefork and worker, in Apache 2.0, and configure APACHE-related core parameters as needed to achieve maximum performance and stability. Below I will compile and install it in worker mode #./configure -- prefix =/opt/Apache -- With-MPM = worker -- enable-module = So this article is contributed by arcclient
PDF files may have poor browsing experience on the WAP side. We recommend that you first select txt or download the source file to your local machine for viewing.
MPM -- Apache Working Mode
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. MPM (Multi-processing modules, multi-channel processing module) is the core feature that affects performance in apache2.0. 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. The following example shows how
How to specify MPM in Apache 2.0. # Tar-xvzf httpd-2.0.59.tar.gz # cd httpd-2.0.59 #. /configure -- help | grep MPM -- 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, that is, the MPM module. BEOs, mpmt_os2
This is the default MPM on BEOs and OS/2, respectively. perchild is designed to run different sub-processes with different identities of users and groups. 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 mainly describe the product-level MPM with the highest performance relationship between prefork and worker. 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. The prefork itself does not use threads, and 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, use "httpd-L" to confirm
Set the currently used mpm, and you will see prefork. C (if you see worker. C, it indicates that worker MPM is used, and so on ). Check the generated httpd by default. the conf configuration file contains the following configuration sections: startservers 5 minspareservers 5 maxspareservers 10 maxclients 150 maxrequestsperchild 0 prefork. The principle is that after the control process initially creates a "startservers" sub-process
To meet the minspareservers settings, you need to create a process, wait for one second, continue to create two, then wait for one second, continue to create four ...... In this way, the number of Created processes is increased exponentially, reaching a maximum of 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 set to a value ratio
Minspareservers is small. Apache automatically adjusts 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, but setting it to a non-zero value also has two important advantages: ◆ can prevent 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. Maxclients is the most important of these commands. It sets the request that Apache can process at the same time and is the parameter that has the greatest impact on Apache performance. The default value of 150 is far from enough. If the total number of requests has reached this value (you can confirm it through PS-Ef | grep HTTP | WC-l), please wait in line for subsequent requests, until a processed request is completed. This is the main reason why there are still a lot of system resources and HTTP access requests are slow. The system administrator can dynamically adjust this parameter based on hardware configuration and load conditions.
Value. In theory, the larger the value, the more requests can be processed, but the default Apache limit cannot exceed 256. If you set this value to greater than 256, Apache cannot start. In fact, 256 is not enough for sites with a slightly higher load. In Apache 1.3, this is a hard limitation. To increase the value, you must manually modify the src/include/httpd under the source code tree before "Configure. find 256 in H, and you will find the line "# define hard_server_limit 256. Change 256 to the value to be increased (for example, 4000)
Then re-compile Apache. Apache, added the serverlimit command in 2.0, so that maxclients can be increased without re-compiling Apache. The following is the author's prefork configuration section: startservers 10 minspareservers 10 maxspareservers 15 serverlimit 2000 maxclients 1000 maxrequestsperchild 10000. In the above configuration, the maximum serverlimit value is 2000, which is sufficient for most sites. If
Make sure to increase the value and modify the following two lines in server/MPM/prefork. C under the source code tree: # define default_server_limit 256 # define max_server_limit 20000
Compared with prefork, worker is a brand new MPM that supports multi-thread and multi-process hybrid models in version 2.0. Because threads are used for processing, a relatively large number of requests can be processed, and the overhead of system resources is smaller than that of process-based servers. However, worker also uses multiple processes, and each process generates multiple threads to achieve stability based on the process server. This kind of MPM will be the trend of Apache 2.0. After configure-with-MPM = worker, make and install it. In the default generated
Httpd. the configuration section in conf is startservers 2 maxclients 150 minsparethreads 25 maxsparethreads 75 threadsperchild 25 maxrequestsperchild 0 worker. The working principle is that the main control process generates a "startservers" sub-process, each sub-process contains a fixed number of threadsperchild threads, and each thread processes Requests independently. Similarly, in order not to generate a thread when the request arrives, minsparethreads and maxsparethreads
The minimum and maximum number of Idle threads are set, while maxclients sets the total number of threads in all sub-processes. If the total number of threads in the existing sub-process cannot meet the load, the control process will derive a new sub-process. The maximum default values of minsparethreads and maxsparethreads are 75 and 250, respectively. These two parameters have little impact on Apache performance and can be adjusted as needed. Threadsperchild is the most performance-related command in worker MPM. The maximum default value of threadsperchild is 64. It is not enough if the load is large.
64 The threadlimit command must be explicitly used, and its maximum default value is 20000. The preceding two values are located in the following two rows in the source code tree server/MPM/worker. C: # define default_thread_limit 64 # define max_thread_limit 20000, which correspond to the number of restrictions of threadsperchild and threadlimit. It is best to go to configure
Previously, we changed 64 to the expected value. Note: Do not set these two values too high to exceed the processing capability of the system, so that the system is unstable because Apache does not start. In worker mode, the total number of requests that can be processed simultaneously is determined by the total number of sub-processes multiplied by the value of threadsperchild. The value must be greater than or equal to maxclients. If the load is large and the number of existing sub-processes cannot exceed the limit, the control process will derive a new sub-process. By default, the maximum number of sub-processes is 16. To increase the number, you must explicitly declare serverlimit (the maximum value is 20000 ). These two values are located in the source code tree server/MPM/worker. C.
# Define default_server_limit 16 # define max_server_limit 20000
Note that if serverlimit is explicitly declared, the value multiplied by threadsperchild must be greater than or equal to maxclients, and maxclients must be an integer multiple of threadsperchild, otherwise, Apache automatically adjusts to a value (which may be an unexpected value ). The following is the worker configuration section of the writer: startservers 3 maxclients 2000 serverlimit 25 minsparethreads 50 maxsparethreads 200 threadlimit
200 threadsperchild 100 maxrequestsperchild 0 through the above description, you can understand the working principles of the two important mpm, prefork and worker in Apache 2.0, and can configure APACHE-related core parameters according to the actual situation, to achieve maximum performance and stability. Next I will compile and install it in worker mode #./configure -- prefix =/opt/Apache -- With-MPM = worker -- enable-module = so

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.