Posted on Leave a comment

How to speed up your apache server with mpm_event

Currently Apache supports three different Multi-Processing Modules (MPMs) that are responsible for opening a socket, processing the request, keeping the connection open for a certain period, handling new events occurring through that connection, and returning the content produced by a program made in a particular language (such as PHP, Perl, or Python).

  1. Prefork: Each process handles one connection at a time and is isolated from the others, so no memory is shared between them. This is the default mode for Apache.
  2. Worker: It uses multiple processes with many threads each. This method of treating connections encourages better resource utilisation, while still maintaining stability.
  3. Event: This MPM_Event was designed to allow more requests to be served simultaneously by enabling the process to manage threads so that some threads are free to handle new incoming connections while others are kept bound to the live connections.

Before we begin you need the following:

  • SSH access to your server, user with root privileges (using sudo) 
  • Apache 2.4.25+
  • Debian 9/10 or Ubuntu 18 +

Now that we are logged in via ssh, disable package connecting the PHP processor to Apache HTTP, since it is no longer necessary

a2dismod php7.3 mpm_prefork

Next you’ll want to add PHP-FPM ( if you haven’t already done so )as a running service to start at boot.

Open the /etc/apt/sources.list file and add contrib and non-free to each source line:

deb http://deb.debian.org/debian/ buster main contrib non-free
deb-src http://deb.debian.org/debian/ buster main contrib non-free

deb http://security.debian.org/debian-security buster/updates main contrib non-free
deb-src http://security.debian.org/debian-security buster/updates main contrib non-free

install Apache, the mod-fastcgi module, and PHP-FPM:

sudo apt-get install apache2 libapache2-mod-fastcgi php7.3-fpm

sudo a2enmod actions

Enabling mpm_event module:

sudo a2enmod mpm_event

systemctl restart apache2

Check that it is running with the following commands:

sudo apachectl -M | grep 'mpm'

sudo apachectl -M | grep 'proxy'

PHP-FPM will handle PHP code more efficiently, and overall resource utilisation has improved. Test below shows the WordPress Web page and all its static files. We used 30 concurrent users over 1 minute and obtained the following results:

MPM_Event speed test

In conclusion:

  • Memory usage is much lower.
  • Much higher data transferred.
  • Less failed transactions and higher transactions rate.

Have any questions, leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *