MPM (Multi processing module) is a component of apache server, that determines how multiple clients or connections shall be handled.
Apache is flexible by design and there are different mpms that can be used with apache depending on the needs. Some MPMs create a separate process to handle each request, whereas some create separate threads.
Some mpms run separate processes with separate uid/gid allowing for improved security.
Some of the common mpms used by Apache web server on Linux:
- 1. Worker
- 2. Prefork
- 3. mpm-ITK
- 4. Peruser
Each of the mpm has its own pros and cons. Apache doc page on mpms is here.
Apache can run only one of them at a time. Mpms are not modules that are loaded by apache. Instead they are compiled into apache.
To check which mpm apache is using run the following command :
Ubuntu
On Ubuntu Apache is called apache2. First locate the apache2 binary.
$ whereis apache2 apache2: /usr/sbin/apache2 /etc/apache2 /usr/lib/apache2 /usr/lib64/apache2 /usr/share/apache2 /usr/share/man/man8/apache2.8.gz
Now run the apache binary with the "l" option. It provides a list of all the modules that have been compiled into apache.
$ /usr/sbin/apache2 -l Compiled in modules: core.c mod_log_config.c mod_logio.c worker.c http_core.c mod_so.c
In the above output it can be see that worker.c has been compiled into apache. So mpm worker is being used.
Another way to determine the mpm is by executing the apache binary with the "V" option :
$ /usr/sbin/apache2 -V Server version: Apache/2.2.17 (Ubuntu) Server built: Nov 3 2011 02:15:48 Server's Module Magic Number: 20051115:25 Server loaded: APR 1.4.2, APR-Util 1.3.9 Compiled using: APR 1.4.2, APR-Util 1.3.9 Architecture: 64-bit Server MPM: Worker threaded: yes (fixed thread count) forked: yes (variable process count) Server compiled with.... -D APACHE_MPM_DIR="server/mpm/worker" -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=128 -D HTTPD_ROOT="/etc/apache2" -D SUEXEC_BIN="/usr/lib/apache2/suexec" -D DEFAULT_PIDLOG="/var/run/apache2.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="mime.types" -D SERVER_CONFIG_FILE="apache2.conf"
It provides various information about the MPM (name , threaded , forked) :
Server MPM: Worker threaded: yes (fixed thread count) forked: yes (variable process count)
A shorter syntax for the above command using grep
$ /usr/sbin/apache2 -V | grep MPM Server MPM: Worker -D APACHE_MPM_DIR="server/mpm/worker"
The process of checking MPMs on Ubuntu should work the same way as on Debian and similar systems.
CentOS
On CentOS Apache is called httpd
# whereis httpd httpd: /usr/sbin/httpd /etc/httpd.old /etc/httpd
List the apache details
# /usr/sbin/httpd -l /usr/sbin/httpd: line 63: ulimit: open files: cannot modify limit: Operation not permitted /usr/sbin/httpd: line 64: ulimit: open files: cannot modify limit: Operation not permitted /usr/sbin/httpd: line 65: ulimit: open files: cannot modify limit: Operation not permitted Compiled in modules: core.c mod_proxy_balancer.c mod_ssl.c prefork.c http_core.c mod_mime.c ......
It shows the prefork.c So mpm prefork is running.
# /usr/sbin/httpd -V /usr/sbin/httpd: line 63: ulimit: open files: cannot modify limit: Operation not permitted /usr/sbin/httpd: line 64: ulimit: open files: cannot modify limit: Operation not permitted /usr/sbin/httpd: line 65: ulimit: open files: cannot modify limit: Operation not permitted Server version: Apache/2.2.17 (Unix) Server built: Feb 12 2011 11:30:46 Cpanel::Easy::Apache v3.2.0 rev5291 Server's Module Magic Number: 20051115:25 Server loaded: APR 1.4.2, APR-Util 1.3.10 Compiled using: APR 1.4.2, APR-Util 1.3.10 Architecture: 32-bit Server MPM: Prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APACHE_MPM_DIR="server/mpm/prefork" -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=128 -D HTTPD_ROOT="/usr/local/apache" -D SUEXEC_BIN="/usr/local/apache/bin/suexec" -D DEFAULT_PIDLOG="logs/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_LOCKFILE="logs/accept.lock" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf"
The mpm information is :
Server MPM: Prefork threaded: no forked: yes (variable process count)
Conclusion
Each MPM has its own advantages and disadvantages.
The Prefork MPM creates multiple child processes each of which handle a request. This is fast and efficient, however does not scale well with huge number of concurrent requests.
The Worker MPM on the other hand creates child processes and threads which can handle multiple concurrent requests a lot efficiently than prefork.
The following discussion on stackoverflow explain the benefits and drawbacks of different apache mpms:
https://serverfault.com/questions/383526/how-do-i-select-which-apache-mpm-to-use
If you have any feedback or questions, let us know in the comments below.
Question. I’m a bit confused about the following line:
Server compiled with….
Doesn’t that indicate that the binary compiled with the directives beneath it, but not necessarily being used?
apache can use only 1 mpm at a time, therefore the mpm with which apache is compiled, is in use.