Httpd worker MPM Configuration: Difference between revisions
(53 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=Internal= | =Internal= | ||
* [[httpd | * [[httpd worker MPM|worker MPM]] | ||
* [[Httpd_Configuration#Subjects|httpd Configuration]] | * [[Httpd_Configuration#Subjects|httpd Configuration]] | ||
Line 7: | Line 7: | ||
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;"> | <blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;"> | ||
:[[Httpd | :[[Httpd worker MPM Concepts#Overview|worker MPM Concepts]] | ||
</blockquote> | </blockquote> | ||
=Configuration Example= | |||
<pre> | |||
<IfModule worker.c> | |||
StartServers 4 | |||
ServerLimit 16 | |||
ThreadLimit 50 | |||
ThreadsPerChild 50 | |||
MinSpareThreads 50 | |||
MaxSpareThreads 300 | |||
MaxRequestsPerChild 0 | |||
MaxClients 300 | |||
</IfModule> | |||
</pre> | |||
=Diagram= | =Diagram= | ||
Line 14: | Line 29: | ||
The configuration elements described below are represented on the [[Mod_jk_Concepts#Diagram|mod_jk Concepts Diagram]]. | The configuration elements described below are represented on the [[Mod_jk_Concepts#Diagram|mod_jk Concepts Diagram]]. | ||
=Enabling | =Sizing Procedure= | ||
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;"> | |||
:[[Httpd mod jk JBoss Sizing|mod_jk JBoss Sizing Procedure]] | |||
</blockquote> | |||
=Enabling worker MPM Mode= | |||
If you configure httpd yourself, make sure you compiled it with worker MPM support. | If you configure httpd yourself, make sure you compiled it with worker MPM support. | ||
Line 23: | Line 44: | ||
<blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;"> | <blockquote style="background-color: #f9f9f9; border: solid thin lightgrey;"> | ||
:[[ | :[[httpd worker MPM Compilation|worker MPM Compilation]] | ||
</blockquote> | </blockquote> | ||
= | =MaxClients, MaxRequestWorkers= | ||
{{External2|http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxclients|http://httpd.apache.org/docs/current/mod/mpm_common.html#maxrequestworkers}} | |||
"MaxClients" and "MaxRequestWorkers" are equivalent, since 2.3.13 "MaxClients" was renamed "MaxRequestWorkers", but for the time being, both names are valid and supported. | |||
= | [[#MaxClients.2C_MaxRequestWorkers|MaxClients]] represents the maximum number of connections that will be processed simultaneously ''by the entire server'', seen as the sum of all active children processes. The default value is 400 = 16 ([[#ServerLimit|ServerLimit]]) * 25 ([[#ThreadsPerChild|ThreadsPerChild]]). The directive restricts the total number of threads that will be available to serve clients. | ||
Any connection attempts over the [[#MaxClients.2C_MaxRequestWorkers|MaxClients]] limit will normally be queued, up to a number based on the [[#ListenBacklog|ListenBacklog]] directive. Once a child process becomes available after handling at least one of its current requests, the connection will then be serviced. | |||
Even if [[#ServerLimit|ServerLimit]] is set to a high value ([[#ThreadsPerChild|ThreadsPerChild]] left to default), the number of concurrent connection ''is'' limited by [[#MaxClients.2C_MaxRequestWorkers|MaxClients]]. This was tested and proven. | |||
The general workings of the worker MPM are described in the [[Httpd worker MPM Concepts#MaxClients|worker MPM concepts page]]. | |||
==Reaching the Upper Limit== | |||
The server detects the fact that the MaxClients limit has been reached and logs this in the error log: | |||
<pre> | |||
[error] server reached MaxClients setting, consider raising the MaxClients setting | |||
</pre> | |||
==MaxClients Idiosyncrasies== | ==MaxClients Idiosyncrasies== | ||
* | * [[#MaxClients.2C_MaxRequestWorkers|MaxClients]] must be at least equals with [[#ThreadsPerChild|ThreadsPerChild]]. If not, httpd will warn at startup and automatically adjust the value to be equals with [[#ThreadsPerChild|ThreadsPerChild]]. | ||
* | * [[#MaxClients.2C_MaxRequestWorkers|MaxClients]] must be an integer multiple of [[#ThreadsPerChild|ThreadsPerChild]]. If it's not, it will be adjusted automatically, and the server will issue an error message similar to the one presented below: | ||
<pre> | <pre> | ||
Line 55: | Line 80: | ||
=ServerLimit= | =ServerLimit= | ||
=ThreadLimit= | {{External|http://httpd.apache.org/docs/current/mod/mpm_common.html#serverlimit}} | ||
Upper limit on configurable number of httpd processes. Default is 16. It is a hard limit, any attempts to change this directive during a restart will be ignored. | |||
Note: if ServerLimit is n, ps will show n + 2 server processes. For a ServerLimit value of 1: | |||
<pre> | |||
[webr@rangiroa ~]$ ps -ef | grep httpd | |||
root 7535 1 0 11:15 ? 00:00:00 /home/webr/httpd-2.2.21-worker/bin/httpd -k start | |||
webr 7536 7535 0 11:15 ? 00:00:00 /home/webr/httpd-2.2.21-worker/bin/httpd -k start | |||
webr 7537 7535 0 11:15 ? 00:00:00 /home/webr/httpd-2.2.21-worker/bin/httpd -k start | |||
</pre> | |||
The first one (7535) is the parent that manages the children that perform the work. It is root-owned. <font color=darkgrey>What is the second one (7536)? </font> The third one (7537) is the actual child. | |||
If [[#ServerLimit|ServerLimit]] is set to a value much higher than necessary, unused shared memory will be allocated. If both [[#ServerLimit|ServerLimit]] and [[#MaxClients |MaxClients]] are set to values higher than the system can handle, Apache may not start or the system may become unstable. | |||
Use this directive only if your [[#MaxClients|MaxClients]] and [[#ThreadsPerChild|ThreadsPerChild]] settings require more than 16 server processes (default). Do not set the value of this directive any higher than the number of server processes required by what you may want for [[#MaxClients|MaxClients]] and [[#ThreadsPerChild|ThreadsPerChild]]. | |||
=StartServers= | |||
* http://httpd.apache.org/docs/current/mod/mpm_common.html#startservers | |||
The [[#StartServers|StartServers]] directive sets the number of child server processes created on startup. Default is 3. As the number of processes is dynamically controlled depending on the load, there is usually little reason to adjust this parameter. | |||
=ThreadsPerChild and ThreadLimit= | |||
{{External2|http://httpd.apache.org/docs/current/mod/mpm_common.html#threadsperchild|http://httpd.apache.org/docs/current/mod/mpm_common.html#threadlimit}} | |||
[[#ThreadsPerChild_and_ThreadLimit|ThreadsPerChild]] directive sets the number of threads created by each child process. ''The child creates these threads at startup and never creates more''. Default in 25. The value of [[#ThreadsPerChild_and_ThreadLimit|ThreadsPerChild]] ''can be modified during a [[Httpd_Concepts#Graceful_Restart|graceful restart]] or a [[Httpd_Concepts#Restart_Now|hard restart]]'', however it cannot be set to a value over [[#ThreadsPerChild_and_ThreadLimit|ThreadLimit]]. | |||
The [[#ThreadsPerChild_and_ThreadLimit|ThreadLimit]] directive sets the maximum configured value for [[#ThreadsPerChild_and_ThreadLimit|ThreadsPerChild]] for the lifetime of the httpd process. Any attempts to change this directive during a restart will be ignored. The default value is 64. There is a hard limit of ThreadLimit 20000 hardcoded into the server. To increase it even further past this limit, you will need to modify the value of MAX_THREAD_LIMIT in the mpm source file and rebuild the server. | |||
It is possible to configure [[#ThreadsPerChild_and_ThreadLimit|ThreadsPerChild]] to a value higher than [[#ThreadsPerChild_and_ThreadLimit|ThreadLimit]], httpd won't complain at startup but the value will be silently ignored and each child will actually create 'ThreadLimit' threads. | |||
For clarity, it's probably best to explicitly configure [[#ThreadsPerChild_and_ThreadLimit|ThreadLimit]] and [[#ThreadsPerChild_and_ThreadLimit|ThreadsPerChild]] to the same value. | |||
ThreadsPerChild influences the number of connections maintained by the proxy workers in their pool. For more details see [[Httpd_mod_proxy_Concepts#Connection_Pooling|mod_proxy Connection Pooling]]. | |||
==ThreadLimit Idiosyncrasies== | |||
Declare [[#ThreadsPerChild_and_ThreadLimit|ThreadLimit]] ''before'' [[#MaxClients.2C_MaxRequestWorkers|MaxClients]] in the configuration file. Doing otherwise would lead to someting similar to (for the below, [[#ThreadsPerChild_and_ThreadLimit|ThreadLimit]] was set to 100, but declared ''after'' [[#MaxClients.2C_MaxRequestWorkers|MaxClients]]): | |||
<pre> | |||
ServerLimit 16 | |||
StartServers 16 | |||
MaxClients 10 | |||
ThreadLimit 100 | |||
ThreadsPerChild 100 | |||
</pre> | |||
<pre> | |||
starting httpd ... WARNING: ThreadsPerChild of 100 exceeds ThreadLimit value of 64 | |||
threads, lowering ThreadsPerChild to 64. To increase, please see the ThreadLimit directive. | |||
</pre> | |||
=ListenBacklog= | =ListenBacklog= | ||
{{External|http://httpd.apache.org/docs/current/mod/mpm_common.html#listenbacklog}} | |||
The maximum length of the queue of pending connections. See the backlog parameter to the listen(2) system call. Default 511. This will often be limited to a smaller number by the operating system. This varies from OS to OS. Also note that many OSes do not use exactly what is specified as the backlog, but use a number based on (but normally larger than) what is set. | |||
=MaxRequestsPerChild= | |||
{{External|http://httpd.apache.org/docs/current/mod/mpm_common.html#maxrequestsperchild}} | |||
Limit on the number of requests that an individual child server will handle during its life. After MaxRequestsPerChild requests, the child process will die. If MaxRequestsPerChild is 0, then the process will never expire. Setting MaxRequestsPerChild to a non-zero value limits the amount of memory that process can consume by (accidental) memory leakage. | |||
The default (compiled-in) value of this setting (10000) is used when no MaxRequestsPerChild directive is present in the configuration. Many default configurations provided with the server include "MaxRequestsPerChild 0" as part of the ''default configuration''. | |||
=MinSpareThreads, MaxSpareThreads= | |||
{{External2|http://httpd.apache.org/docs/current/mod/mpm_common.html#minsparethreads|http://httpd.apache.org/docs/current/mod/mpm_common.html#maxsparethreads}} | |||
Minimum and maximum number of idle threads available to handle request spikes. Both values are server-wide - apply to all processes. The MinSpareThreads default value is 75. | |||
If there aren't enough idle threads in the server then child processes are created until the number of idle threads is greater than number. For a detailed explanation of how these parameters work, see {{Internal|Httpd worker MPM Concepts#spare|worker MPM Concepts}} |
Latest revision as of 04:43, 9 January 2017
Internal
Overview
Configuration Example
<IfModule worker.c> StartServers 4 ServerLimit 16 ThreadLimit 50 ThreadsPerChild 50 MinSpareThreads 50 MaxSpareThreads 300 MaxRequestsPerChild 0 MaxClients 300 </IfModule>
Diagram
The configuration elements described below are represented on the mod_jk Concepts Diagram.
Sizing Procedure
Enabling worker MPM Mode
If you configure httpd yourself, make sure you compiled it with worker MPM support.
If you use Red Hat EWS, worker support comes pre-compiled into $APACHE_HOME/sbin/httpd.worker, make sure the start script is using that.
For more details about compiling httpd with the right MPM mode, see:
MaxClients, MaxRequestWorkers
"MaxClients" and "MaxRequestWorkers" are equivalent, since 2.3.13 "MaxClients" was renamed "MaxRequestWorkers", but for the time being, both names are valid and supported.
MaxClients represents the maximum number of connections that will be processed simultaneously by the entire server, seen as the sum of all active children processes. The default value is 400 = 16 (ServerLimit) * 25 (ThreadsPerChild). The directive restricts the total number of threads that will be available to serve clients.
Any connection attempts over the MaxClients limit will normally be queued, up to a number based on the ListenBacklog directive. Once a child process becomes available after handling at least one of its current requests, the connection will then be serviced.
Even if ServerLimit is set to a high value (ThreadsPerChild left to default), the number of concurrent connection is limited by MaxClients. This was tested and proven.
The general workings of the worker MPM are described in the worker MPM concepts page.
Reaching the Upper Limit
The server detects the fact that the MaxClients limit has been reached and logs this in the error log:
[error] server reached MaxClients setting, consider raising the MaxClients setting
MaxClients Idiosyncrasies
- MaxClients must be at least equals with ThreadsPerChild. If not, httpd will warn at startup and automatically adjust the value to be equals with ThreadsPerChild.
- MaxClients must be an integer multiple of ThreadsPerChild. If it's not, it will be adjusted automatically, and the server will issue an error message similar to the one presented below:
MaxClients (12) is not an integer multiple of ThreadsPerChild (10), lowering MaxClients to 10
ServerLimit
Upper limit on configurable number of httpd processes. Default is 16. It is a hard limit, any attempts to change this directive during a restart will be ignored.
Note: if ServerLimit is n, ps will show n + 2 server processes. For a ServerLimit value of 1:
[webr@rangiroa ~]$ ps -ef | grep httpd root 7535 1 0 11:15 ? 00:00:00 /home/webr/httpd-2.2.21-worker/bin/httpd -k start webr 7536 7535 0 11:15 ? 00:00:00 /home/webr/httpd-2.2.21-worker/bin/httpd -k start webr 7537 7535 0 11:15 ? 00:00:00 /home/webr/httpd-2.2.21-worker/bin/httpd -k start
The first one (7535) is the parent that manages the children that perform the work. It is root-owned. What is the second one (7536)? The third one (7537) is the actual child.
If ServerLimit is set to a value much higher than necessary, unused shared memory will be allocated. If both ServerLimit and MaxClients are set to values higher than the system can handle, Apache may not start or the system may become unstable.
Use this directive only if your MaxClients and ThreadsPerChild settings require more than 16 server processes (default). Do not set the value of this directive any higher than the number of server processes required by what you may want for MaxClients and ThreadsPerChild.
StartServers
The StartServers directive sets the number of child server processes created on startup. Default is 3. As the number of processes is dynamically controlled depending on the load, there is usually little reason to adjust this parameter.
ThreadsPerChild and ThreadLimit
ThreadsPerChild directive sets the number of threads created by each child process. The child creates these threads at startup and never creates more. Default in 25. The value of ThreadsPerChild can be modified during a graceful restart or a hard restart, however it cannot be set to a value over ThreadLimit.
The ThreadLimit directive sets the maximum configured value for ThreadsPerChild for the lifetime of the httpd process. Any attempts to change this directive during a restart will be ignored. The default value is 64. There is a hard limit of ThreadLimit 20000 hardcoded into the server. To increase it even further past this limit, you will need to modify the value of MAX_THREAD_LIMIT in the mpm source file and rebuild the server.
It is possible to configure ThreadsPerChild to a value higher than ThreadLimit, httpd won't complain at startup but the value will be silently ignored and each child will actually create 'ThreadLimit' threads.
For clarity, it's probably best to explicitly configure ThreadLimit and ThreadsPerChild to the same value.
ThreadsPerChild influences the number of connections maintained by the proxy workers in their pool. For more details see mod_proxy Connection Pooling.
ThreadLimit Idiosyncrasies
Declare ThreadLimit before MaxClients in the configuration file. Doing otherwise would lead to someting similar to (for the below, ThreadLimit was set to 100, but declared after MaxClients):
ServerLimit 16 StartServers 16 MaxClients 10 ThreadLimit 100 ThreadsPerChild 100
starting httpd ... WARNING: ThreadsPerChild of 100 exceeds ThreadLimit value of 64 threads, lowering ThreadsPerChild to 64. To increase, please see the ThreadLimit directive.
ListenBacklog
The maximum length of the queue of pending connections. See the backlog parameter to the listen(2) system call. Default 511. This will often be limited to a smaller number by the operating system. This varies from OS to OS. Also note that many OSes do not use exactly what is specified as the backlog, but use a number based on (but normally larger than) what is set.
MaxRequestsPerChild
Limit on the number of requests that an individual child server will handle during its life. After MaxRequestsPerChild requests, the child process will die. If MaxRequestsPerChild is 0, then the process will never expire. Setting MaxRequestsPerChild to a non-zero value limits the amount of memory that process can consume by (accidental) memory leakage.
The default (compiled-in) value of this setting (10000) is used when no MaxRequestsPerChild directive is present in the configuration. Many default configurations provided with the server include "MaxRequestsPerChild 0" as part of the default configuration.
MinSpareThreads, MaxSpareThreads
Minimum and maximum number of idle threads available to handle request spikes. Both values are server-wide - apply to all processes. The MinSpareThreads default value is 75.
If there aren't enough idle threads in the server then child processes are created until the number of idle threads is greater than number. For a detailed explanation of how these parameters work, see