Apache Prefork vs Worker MPM
For instance on a Windows installation you might get something like: As of version 2.2 this is the list of available core features and MPM modules: — Core Apache HTTP Server features that are always available — A collection of directives that are implemented by more than one multi-processing module (MPM) — This Multi-Processing Module is optimized for BeOS. Question: I need to change MPM prefork module to worker but it’s not working on my Debian 9.1.
Apache Prefork vs Worker MPM
Looking at the Apache config file, I see Prefork and Worker MPM defined. What is the difference and which one is Apache using?
Prefork and worker are two type of MPM apache provides. Both have their merits and demerits.
By default mpm is prefork which is thread safe.
Prefork MPM uses multiple child processes with one thread each and each process handles one connection at a time.
Worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time.
For more details you can visit https://httpd.apache.org/docs/2.4/mpm.html and https://httpd.apache.org/docs/2.4/mod/prefork.html
Apache’s Multi-Processing Modules (MPMs) are responsible for binding to network ports on the machine, accepting requests, and dispatching children to handle the requests (http://httpd.apache.org/docs/2.2/mpm.html).
They’re like any other Apache module, except that just one and only one MPM must be loaded into the server at any time . MPMs are chosen during configuration and compiled into the server by using the argument —with-mpm=NAME with the configure script where NAME is the name of the desired MPM.
Apache will use a default MPM for each operating system unless a different one is choosen at compile-time (for instance on Windows mpm_winnt is used by default). Here’s the list of operating systems and their default MPMs:
- BeOS beos
- Netware mpm_netware
- OS/2 mpmt_os2
- Unix/Linux prefork ( update for Apache version ≥ 2.4: prefork , worker , or event , depending on platform capabilities)
- Windows mpm_winnt
To check what modules are compiled into the server use the command-line option -l (here is the documentation). For instance on a Windows installation you might get something like:
> httpd -l Compiled in modules: core.c mod_win32.c mpm_winnt.c http_core.c mod_so.c
As of version 2.2 this is the list of available core features and MPM modules:
- core — Core Apache HTTP Server features that are always available
- mpm_common — A collection of directives that are implemented by more than one multi-processing module (MPM)
- beos — This Multi-Processing Module is optimized for BeOS.
- event — An experimental variant of the standard worker MPM
- mpm_netware Multi-Processing Module implementing an exclusively threaded web server optimized for Novell NetWare
- mpmt_os2 Hybrid multi-process, multi-threaded MPM for OS/2
- prefork Implements a non-threaded, pre-forking web server
- mpm_winnt — This Multi-Processing Module is optimized for Windows NT.
- worker — Multi-Processing Module implementing a hybrid multi-threaded multi-process web server
Now, to the difference between prefork and worker .
implements a non-threaded, pre-forking web server that handles requests in a manner similar to Apache 1.3. It is appropriate for sites that need to avoid threading for compatibility with non-thread-safe libraries. It is also the best MPM for isolating each request, so that a problem with a single request will not affect any other.
The worker MPM implements a hybrid multi-process multi-threaded server and gives better performance, hence it should be preferred unless one is using other modules that contain non-thread-safe libraries (see also this discussion or this on Serverfault).
Take a look at this for more detail. It refers to how Apache handles multiple requests. Preforking, which is the default, starts a number of Apache processes (2 by default here, though I believe one can configure this through httpd.conf). Worker MPM will start a new thread per request, which I would guess, is more memory efficient. Historically, Apache has used prefork, so it’s a better-tested model. Threading was only added in 2.0.
For CentOS 6.x and 7.x (including Amazon Linux) use:
This will show you which of the MPMs are configured. Either prefork, worker, or event. Prefork is the earlier, threadsafe model. Worker is multi-threaded, and event supports php-mpm which is supposed to be a better system for handling threads and requests.
However, your results may vary, based on configuration. I’ve seen a lot of instability in php-mpm and not any speed improvements. An aggressive spider can exhaust the maximum child processes in php-mpm quite easily.
The setting for prefork, worker, or event is set in sudo nano /etc/httpd/conf.modules.d/00-mpm.conf (for CentOS 6.x/7.x/Apache 2.4).
# Select the MPM module which should be used by uncommenting exactly # one of the following LoadModule lines: # prefork MPM: Implements a non-threaded, pre-forking web server # See: http://httpd.apache.org/docs/2.4/mod/prefork.html #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so # worker MPM: Multi-Processing Module implementing a hybrid # multi-threaded multi-process web server # See: http://httpd.apache.org/docs/2.4/mod/worker.html #LoadModule mpm_worker_module modules/mod_mpm_worker.so # event MPM: A variant of the worker MPM with the goal of consuming # threads only for connections with active processing # See: http://httpd.apache.org/docs/2.4/mod/event.html #LoadModule mpm_event_module modules/mod_mpm_event.so
How can I change from prefork to worker MPM on, I’m running CentOS 64 bit, and just found out I am running prefork MPM on my dual quad Xeon. I was told worker will give me lower memory usage and higher performance, since I run a very high traffic website. If this is true, how do I do it? apache-2.2 centos mpm-worker mpm-prefork.
Should I use MPM prefork or MPM event in apache?
I am using Ubuntu 16.04 LTS with apache/2.4.18. I need to know which MPM module should I use whether MPM_prefork (which is default in my case) or MPM_event (which is a newly built module). It must be noted that we are dealing with huge traffic on webserver with configuration of 16-GB RAM and 8-cores CPU.
See this article for a good overview of the 3 main MPMs.
My suggestion would be to consider going with Event MPM as it should be better at dealing with high loads.
How To Tune Apache prefork mpm values on linux Server, The only thing I would like to change is MaxRequestWorkers value from 250 to 400.
Change Apache MPM from prefork to worker
I need to change MPM prefork module to worker but it’s not working on my Debian 9.1. When I enable worker module, PHP is not working. I can’t enable php7.0 module back.
Here is the output from console:
root@Debian-91-stretch-64-LAMP ~ # apachectl -V | grep -i mpm
AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 2a01:4f8:171:fc2::2. Set the ‘ServerName’ directive globally to suppress this message
root@Debian-91-stretch-64-LAMP ~ # a2enmod mpm_worker
Considering conflict mpm_event for mpm_worker: Considering conflict mpm_prefork for mpm_worker: ERROR: Module mpm_prefork is enabled — cannot proceed due to conflicts. It needs to be disabled first!
root@Debian-91-stretch-64-LAMP ~ # a2dismod mpm_prefork
ERROR: The following modules depend on mpm_prefork and need to be disabled first: php7.0 root@Debian-91-stretch-64-LAMP ~ # a2dismod php7.0 Module php7.0 disabled.
To activate the new configuration, you need to run:
root@Debian-91-stretch-64-LAMP ~ # a2dismod php7.0
To activate the new configuration, you need to run:
systemctl restart apache2
root@Debian-91-stretch-64-LAMP ~ # a2enmod mpm_worker
Considering conflict mpm_event for mpm_worker:
Considering conflict mpm_prefork for mpm_worker:
Enabling module mpm_worker.
To activate the new configuration, you need to run:
systemctl restart apache2
root@Debian-91-stretch-64-LAMP ~ # a2enmod php7.0
Considering dependency mpm_prefork for php7.0:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
ERROR: Module mpm_worker is enabled — cannot proceed due to conflicts. It needs to be disabled first!
ERROR: Could not enable dependency mpm_prefork for php7.0, aborting
I got the following error
sudo a2enmod php7.2 Considering dependency mpm_prefork for php7.2: Considering conflict mpm_event for mpm_prefork: ERROR: Module mpm_event is enabled - cannot proceed due to conflicts. It needs to be disabled first! Considering conflict mpm_worker for mpm_prefork: ERROR: Could not enable dependency mpm_prefork for php7.2, aborting
sudo a2dismod mpm_event sudo a2enmod php7.2 sudo systemctl restart apache2
you might also want to try restarting your server
Can’t enable mpm_prefork with Apache 2.4 on Ubuntu, a2enmod mpm_event I get this: Considering conflict mpm_worker for mpm_event: Considering conflict mpm_prefork for mpm_event: Considering conflict mpm_itk for mpm_event: How do I solve the conflict? EDIT2: I used . a2dismod on . mpm_event_module and loaded the mpm_prefork_module. …
Change apache mpm from event to prefork
I recently installed Apache/2.4.6 from source. At present the MPM module enabled is mpm_event_module. I want to enable the prefork mpm, but not sure from where to do that. I am aware of changing the mpm module from /etc/sysconfig/httpd in case of the apache installed using yum. But in my case as the installinon is from source, I could not not do the same. I tried recompiling apche using ‘./configure —prefix=/usr/local/apache —enable-module=prefork’ , but the mpm is still mpm_event_module. Clearly the issue is with defining prefork as the mpm.
I could also see that the installation directory has the prefork.c module. There must be a way to define it as the mpm.
Could someone please help.
In versions prior to 2.4, you cannot change the MPM of the binary Apache2 installation at run-time.
You have to compile apache with the desired MPM using the —with-mpm=MODULE NAME command line option to the config script. To change MPM, the binary must be rebuilt.
You can determine which MPM Apache2 is currently built with by executing apache2 -l or httpd -l on the command line.
Brief but very clear documentation on this:
In version 2.4, you can also build MPMs as dynamic modules which allows changing the MPM at run-time.
How to optimize prefork mpm for high traffic?, If you want to be able to handle high traffic, your best option were to use a worker apache (or even an other type of http server) for static file serving, and a prefork-based (I suggest you mpm-itk) for dynamic languages (probably for php). The worker should forward the dynamic requests to the prefork-based server.