Difference between revisions of "Tune apache2 for more concurrent connections"

(The problem)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
=The problem=
+
= Apache Configuration =
 +
 
 +
== MPM Module ==
 +
 
 +
Please ensure that your apache is using the <code>mpm_worker</code> or <code>mpm_event</code> module. This allows us to serve lots of concurrent connections by using less RAM than with <code>mpm_prefork</code> as we are going to start much less processes. Unfortunately the default MPM module seems to differ from distro to distro, so doublecheck and make sure you are on the right setting.
 +
 
 +
The method to configure the MPM module differes of course also from distribution to distribution:
 +
 
 +
* CentOS7/RHEL7: adjust <code>/etc/httpd/conf.modules.d/00-mpm.conf</code>
 +
* Debian: use <code>a2dismod</code> / <code>a2enmod</code> to disable the wrong and enable the desired MPM Module.
 +
 
 +
About <code>mpm_worker</code> vs <code>mpm_event</code>: we assume they are equivalent for our purpose. <code>mpm_worker</code> is the older one and just works fine. <code>mpm_event</code> should improve on it further but we have been unable to observe any actual advantages.
 +
 
 +
== Concurrent Connections ==  
 +
 
 
By default apache2 is configured to support 150 concurrent connections.
 
By default apache2 is configured to support 150 concurrent connections.
 
This forces all parallel requests beyond that limit to wait.  
 
This forces all parallel requests beyond that limit to wait.  
 
Especially if, for example, active sync clients maintain a permanent connection for push events to arrive.
 
Especially if, for example, active sync clients maintain a permanent connection for push events to arrive.
  
=The solution=
+
This is an example configuration to provide 8000 concurrent connections.
This is an example configuration to provide 800 concurrent connections.
 
Please ensure that your apache is using the mpm_worker module. This allows us to serve lots of concurrent connections by using less RAM than with mpm_prefork as we are going to start much less processes.
 
  
 
<pre><nowiki>
 
<pre><nowiki>
 
<IfModule mpm_worker_module>
 
<IfModule mpm_worker_module>
     ServerLimit         25
+
     ServerLimit             250
     StartServers         10
+
     StartServers             10
     MinSpareThreads     75
+
     MinSpareThreads           75
     MaxSpareThreads     250  
+
     MaxSpareThreads         250  
     ThreadLimit         64
+
     ThreadLimit               64
     ThreadsPerChild     32
+
     ThreadsPerChild           32
     MaxClients          800
+
     MaxRequestWorkers      8000
     MaxRequestsPerChild  0
+
     MaxConnectionsPerChild 10000
 
</IfModule>
 
</IfModule>
 
</nowiki></pre>
 
</nowiki></pre>
  
 +
Note: MaxRequestWorkers was previously named MaxClients and MaxConnectionsPerChild was previously named MaxRequestsPerChild. If you are using old (pre 2.4) verions of apache you might need to use the old names.
  
 
+
Short explanation of the parameters:
==Short explanation of the parameters:==
 
  
 
<table border="1" cellpadding="5" cellspacing="0">
 
<table border="1" cellpadding="5" cellspacing="0">
Line 42: Line 54:
 
</tr>
 
</tr>
 
<tr>
 
<tr>
<td><b>MaxClients</b></td><td>This declares how many concurrent connections we provide. Devided by '''ThreadsPerChild'''  you get the suitable ServerLimit value. May be less than '''ServerLimit * ThreadsPerChild''' to reserve some resources that can be engaged during runtime with increasing '''MaxClients''' and reloading the configuration.</td>
+
<td><b>MaxRequestWorkers</b></td><td>This declares how many concurrent connections we provide. Devided by '''ThreadsPerChild'''  you get the suitable ServerLimit value. May be less than '''ServerLimit * ThreadsPerChild''' to reserve some resources that can be engaged during runtime with increasing '''MaxRequestWorkers''' and reloading the configuration.</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
<td><b>MaxRequestsPerChild</b></td><td>Defines the number of Connections that a process can handle during its lifetime (keep-alives are counted once). After that it will be killed.</td>
+
<td><b>MaxConnectionsPerChild</b></td><td>Defines the number of Connections that a process can handle during its lifetime (keep-alives are counted once). After that it will be killed. This can be used to prevent possible apache memory leaks. If set to 0 the lifetime is infinite.</td>
 
</tr>
 
</tr>
 
</table>
 
</table>
  
  
For further information on these parameters see http://httpd.apache.org/docs/2.2/mod/worker.html and http://httpd.apache.org/docs/2.2/mod/mpm_common.html.
+
For further information on these parameters see http://httpd.apache.org/docs/2.4/mod/worker.html and http://httpd.apache.org/docs/2.4/mod/mpm_common.html.
  
 
--[[User:Steffen.templin|Steffen.templin]] 12:10, 23 May 2011 (UTC)
 
--[[User:Steffen.templin|Steffen.templin]] 12:10, 23 May 2011 (UTC)

Latest revision as of 10:11, 6 September 2018

Apache Configuration

MPM Module

Please ensure that your apache is using the mpm_worker or mpm_event module. This allows us to serve lots of concurrent connections by using less RAM than with mpm_prefork as we are going to start much less processes. Unfortunately the default MPM module seems to differ from distro to distro, so doublecheck and make sure you are on the right setting.

The method to configure the MPM module differes of course also from distribution to distribution:

  • CentOS7/RHEL7: adjust /etc/httpd/conf.modules.d/00-mpm.conf
  • Debian: use a2dismod / a2enmod to disable the wrong and enable the desired MPM Module.

About mpm_worker vs mpm_event: we assume they are equivalent for our purpose. mpm_worker is the older one and just works fine. mpm_event should improve on it further but we have been unable to observe any actual advantages.

Concurrent Connections

By default apache2 is configured to support 150 concurrent connections. This forces all parallel requests beyond that limit to wait. Especially if, for example, active sync clients maintain a permanent connection for push events to arrive.

This is an example configuration to provide 8000 concurrent connections.

<IfModule mpm_worker_module>
    ServerLimit              250
    StartServers              10
    MinSpareThreads           75
    MaxSpareThreads          250 
    ThreadLimit               64
    ThreadsPerChild           32
    MaxRequestWorkers       8000
    MaxConnectionsPerChild 10000
</IfModule>

Note: MaxRequestWorkers was previously named MaxClients and MaxConnectionsPerChild was previously named MaxRequestsPerChild. If you are using old (pre 2.4) verions of apache you might need to use the old names.

Short explanation of the parameters:

ServerLimitDeclares the maximum number of running apache processes. If you change this value you have to restart the daemon.
StartServersThe number of processes to start initially when starting the apache daemon.
MinSpareThreads/MaxSpareThreadsThis regulates how many threads may stay idle without being killed. Apache regulates this on its own very well with default values.
ThreadsPerChildHow many threads can be created per process. Can be changed during a reload.
ThreadLimitThreadsPerChild can be configured as high as this value during runtime. If you change this value you have to restart the daemon.
MaxRequestWorkersThis declares how many concurrent connections we provide. Devided by ThreadsPerChild you get the suitable ServerLimit value. May be less than ServerLimit * ThreadsPerChild to reserve some resources that can be engaged during runtime with increasing MaxRequestWorkers and reloading the configuration.
MaxConnectionsPerChildDefines the number of Connections that a process can handle during its lifetime (keep-alives are counted once). After that it will be killed. This can be used to prevent possible apache memory leaks. If set to 0 the lifetime is infinite.


For further information on these parameters see http://httpd.apache.org/docs/2.4/mod/worker.html and http://httpd.apache.org/docs/2.4/mod/mpm_common.html.

--Steffen.templin 12:10, 23 May 2011 (UTC)