How do you increase the max number of concurrent connections in Apache?

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. Please ensure that your apache is using the mpm_worker. 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. (mpm_event, which is stated to be stable by Apache nowadays, shows problems in load tests, with connection timeouts.)

<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) version of Apache you might need to use the old names.

The short explanation of the parameters:

ServerLimit Declares the maximum number of running apache processes. If you change this value you have to restart the daemon.
StartServers The number of processes to start initially when starting the apache daemon.
MinSpareThreads/MaxSpareThreads This regulates how many threads may stay idle without being killed. Apache regulates this on its own very well with default values.
ThreadsPerChild How many threads can be created per process. Can be changed during a reload.
ThreadLimit ThreadsPerChild can be configured as high as this value during runtime. If you change this value you have to restart the daemon.
MaxRequestWorkers This declares how many concurrent connections we provide. Divided by ThreadsPerChild you get the suitable ServerLimit value. Maybe less than ServerLimit * ThreadsPerChild to reserve some resources that can be engaged during runtime with increasing MaxRequestWorkers and reloading the configuration.
MaxConnectionsPerChild 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.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s