What are Apache MPMs?

Apache: What are Apache MPMs?

Since Apache 2, Multi-Processing Modules (MPMs) have existed. They are modules that change how the Apache servers handles requests and listens to connections.

Common Apache MPMs include prefork, worker, and event. There are different MPMs for different operating systems - these three are for Unix based systems. See the list here for other operating system's MPMs.

How to decide what MPM your Unix-like system (i.e. Linux, BSD, Mac OS, etc) will use?

In the case of Unix, the decision as to which MPM is installed is based on two questions:

1. Does the system support threads?

2. Does the system support thread-safe polling (Specifically, the kqueue and epoll functions)?

If the answer to both questions is 'yes', the default MPM is event.

If The answer to #1 is 'yes', but the answer to #2 is 'no', the default will be worker.

If the answer to both questions is 'no', then the default MPM will be prefork.

In practical terms, this means that the default will almost always be event, as all modern operating systems support these two features.

How to check what MPM your installation of Apache is using?

Run the following command:

httpd -V | grep -i 'mpm'

The output from my Mac computer:

Server MPM:     prefork

The output from my linux VM:

Server MPM:     event

What is the prefork MPM? The preform module let's Apache work in a non-threaded, pre-forking way. Every one of the child processes that Apache has will have one single thread, and only processes one request at a time. It is the default type of MPM. This MPM is thread safe.

What is the Event Apache MPM? The Event MPM uses less resources than the other two described on this page. Each process can contain multiple threads. However, each thread can handle more than one task at a time. The event MPM works with Apache 2.2, however it is not fully compatible. It is recommended to use a minimum of Apache 2.4 when using the event MPM. (But there are plenty of high traffic sites using the event MPM and 2.2 without problems).

What is the worker mpm? The worker MPM lets Apache run as a multi threaded, multi process server. Each child process can have more than one thread. This means that Apache can handle a greater number of requests, while using fewer resources than the prefork MPM. The Worker MPM is commonly used with high traffic web servers on more recent versions of Apache. This MPM is not thread safe.

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about What are Apache MPMs?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Apache language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

What are generators in PHP, and how do they compare to arrays?

How to show a specific view file for certain error codes?

How to view all installed PHP modules?

Push vs Pop vs Shift vs Unshift

How to group a SQL statement in brackets/parenthesis

How to set custom HTTP headers in Apache (by editing .htaccess)

How to destroy or remove a cookie in PHP

How to set up custom error pages in .htaccess for your Apache server (ErrorDocument)

What is the difference between empty(), isset(), != null, is_null() in PHP

What are some ways you can log debug messages and data in JS?