Apache Multi-Processing Modules (MPM): Prefork versus Worker

Refers to:

  • Plesk 12.5 for Linux
  • Plesk 12.0 for Linux
  • Plesk 9.x and below for Linux

Created:

2016-11-16 13:24:31 UTC

Modified:

2017-02-24 12:08:29 UTC

3

Was this article helpful?


Have more questions?

Submit a request

Apache Multi-Processing Modules (MPM): Prefork versus Worker

Resolution

Prefork :

The prefork MPM uses multiple child processes with one thread each. Each process handles one connection at a time. On many systems, prefork is comparable in speed to worker, but uses more memory. Prefork's threadless design has advantages over worker in some situations: it can be used with non-thread-safe third-party modules, and it is easier to debug on platforms with poor thread debugging support.

Advantages :

  • Developed in Apache 1
  • Multiple child processes, 1 thread per child process, child processes handle requests
  • Better isolation and stability
  • Tested to work correctly with Plesk

Disadvantages :

  • Has higher memory consumption and lower performance over the threaded MPMs

Worker :

The worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time. Worker is generally a good choice for high-traffic servers because it has a smaller memory footprint than the prefork MPM.

Advantages :

  • Developed in Apache 2 in addition to prefork module

  • Multiple processes, many threads per process, threads handle requests

  • Uses less memory and provides higher performance

Disadvantages :

  • Does not provide the same level of isolation request-to-request as a process-based MPM does

  • If single thread is suspended/out of control, the entire process will be terminated, affecting all of the threads

  • Requires a thread-safe processor to handle dynamic content

  • Not supported by Plesk

Each module has a different set of the configuration directives in the Apache webserver configuration file:

Prefork:

<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild 4000
</IfModule>

Worker:

<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

Information:

In the RedHat-based Linux distributions, Apache webserver is configured to run with the prefork module by default. Technically, you could switch it to "worker" if you decide that this would suit your needs better, however keep in mind the warning below.

Warning: Plesk was not tested with Apache MPM worker and installing it on Debian/Ubuntu will lead to removal of psa package.

If you still wish to switch to worker module, it is sufficient to uncomment this directive in /etc/sysconfig/httpd file:

# grep HTTPD= /etc/sysconfig/httpd
#HTTPD=/usr/sbin/httpd.worker

and restart Apache:

# /etc/init.d/httpd restart

Note, that the worker MPM assumes a special PHP module to be configured/loaded by the Apache webserver:

# cat /etc/httpd/conf.d/php.conf|grep -A3 "worker.c"
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>

In the end, the question that is frequently asked by customers and engineers is: how to determine which MPM module the server is running on?

First, use ps utility to determine the command line of running Apache process:

 # ps aux | grep -v grep | egrep "apache|httpd"
root      1684  0.0  1.4 284484 14888 ?        Ss   17:52   0:00 /usr/sbin/httpd
apache    3101  0.0  0.7 284484  7596 ?        S    18:02   0:00 /usr/sbin/httpd

and check which module it is running by using this command:

 # /usr/sbin/httpd -l | egrep "prefork|worker"

Alternatively, check /etc/sysconfig/httpd configuration file:

 # grep -B 5 HTTPD= /etc/sysconfig/httpd
# The default processing model (MPM) is the process-based
# "prefork" model. A thread-based model, "worker," is also
# available, but does not work with some modules (such as PHP).
# The service must be stopped before changing this variable.
#
#HTTPD=/usr/sbin/httpd.worker

Additional information

Apache MPM prefork

Apache MPM worker

Have more questions? Submit a request
Please sign in to leave a comment.