How To Increase Max Connections in Apache

Last updated on August 10th, 2020 at 03:05 am

By default, Apache web server is configured to support 150 concurrent connections. As your website traffic increases, Apache will start dropping additional requests and this will spoil customer experience. Here’s how to increase max connections in Apache, to support high traffic websites.

 

How To Increase Max Connections in Apache

Here are the steps to increase max connections in Apache.

 

1. Install MPM module

We need to install MPM Apache module to be able to serve lots of concurrent connections. You can use mpm_worker or mpm_event module for this, instead of mpm_prefork module which consumes a lot of memory.

You can easily install MPM module in Apache with following command

CentOS7/RHEL7: adjust /etc/httpd/conf.modules.d/00-mpm.conf

Comment the line LoadModule mpm_prefork_module modules/mod_mpm_prefork.so by adding # in front of it

Uncomment the line LoadModule mpm_worker_module modules/mod_mpm_worker.so by removing # in front of it.

 

Ubuntu/Debian: use a2dismod / a2enmod to disable mpm_prefork and enable mpm_worker

$ a2dismod mpm_prefork
$ a2enmod mpm_worker

 

2. Increase Max Connections in Apache

Open MPM configuration file:

CentOS/RHEL

$ sudo vi /etc/httpd/conf.modules.d/00-mpm.conf

Ubuntu/Debian

$ sudo vi /etc/apache2/mods-available/mpm_worker.conf

 

You will see the following lines

StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 0

You can change them to the following configuration which supports upto 8000 concurrent users

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

You can also add the above lines to Apache web server configuration file, or Virtual host configuration file.

Let’s quickly look at the parameters

  • Serverlimit – Maximum number of Apache processes
  • StartServers – Number of processes to start when you start running Apache
  • MinSpareThreads/MaxSpareThreads – Number of threads to keep idle without being killed
  • ThreadsPerChild – Number of threads per process
  • MaxRequestWorkers – Number of concurrent connections to be supported. This is the main directive that you need to change to increase max connections in Apache
  • MaxConnectionsPerChild – Number of connections to be handled by each child before it is killed

 

3. Restart Apache Server

Restart Apache web server to Apply changes.

Ubuntu/Debian

$ sudo service apache2 restart

CentOS/Redhat/Fedora

$ sudo service httpd restart

 

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!