Simple tip for anybody still running Apache servers…switch to MPM Event!
What is MPM Event and how does it improve your server performance without any drawbacks?
- I switched to MPM Event, I loved it. And you should do it too!
We’ll cover some minor basics of MPM’s and why MPM Event is the best.
Apache 2 introduced multi-processing modules (aka MPM’s) that change the way servers processed incoming requests. This was probably a natural evolution to optimize for multi-core CPU’s used in server environments. The idea was to write these modules to use the multi-cores more effectively, processing more requests without issues.
As a quick FYI: most of you will not have access to change this unless you’re on a VPS and/or have root access to server.
Apache MPMs – Prefork vs Worker vs Event
By default, Apache servers typically have 3 threads available:
- Implements a non-threaded, pre-forking web server.
- The default one, most stable and also compatible with older software. Unfortunately, also the slowest.
- I’m guessing it’s called that because it’s the original version before they forked off into the other versions.
- You will almost always find this one installed by default as many companies are too lazy to reconfigure hundreds of their servers. There’s also a shady skepticism that they don’t want your server to perform that well since they want to upsell you to a bigger server sooner.
- Multi-Processing Module implementing a hybrid multi-threaded multi-process web server.
- Faster than prefork and can handle more visitors.
- A variant of the worker MPM with the goal of consuming threads only for connections with active processing.
- The fastest MPM and considered least stable…although fine for most people in real-world practices.
- Uses the least resources and can handle the most visits.
What’s the verdict?
Go with MPM Event first. You can switch over to it easy. A few command line entries or also a simple switch in EasyApache if you have WHM/cPanel (show in the image above).
If you have problems, then try Worker and that last is Prefork. Some people noticed faster performance with Prefork or Worker. It can depend on the type of website you have, CPU, ram use, etc. But generally with a high performance server looking to serve many visitors fast, I always recommend MPM Event.
Other reading for you:
Good stuff, I’ll give Event a go. Thanks for a clear article with a clear recommendation. The other searches I did all explained the differences but none actually clearly made a recommendation on whether I should go Event or Worker!
Haha yeah. Modern web servers (pretty much anything after 2010) have long defaulted towards EVENT-DRIVEN which offers better performance while using fewer resources due to better utilization of multi-threaded CPUs. It’s been this way for so long that nobody explains it anymore since it’s assumed. The only confusion is that there are still some legacy apps which default to older process-based MPM’s like Worker or Prefork under the (somewhat) misbelief that they are more stable or “safer” setting for the average web-server.
You’re right, nobody does explain it in quite the right way!
I’ve chucked it on Event, installed all of my usual scripts, and have found zero incompatabilities. Not sure exactly what “legacy apps” refers to, but it makes it sound like it means software from the 1990s! Does make me wonder if anyone has switched to Event and had incompatabilites, but I certainly haven’t heard or seen much about it if they have 😛
mpm has bugs. strange bugs. I was a big fan of it ever since, however if you have heavy loads to handle you will start noticing sporadic 500 errors and at some point full stop with all legs up situation where a manual restart is required to get it back on feet.
this behaviour has been much worse a few years ago when they (marked as) fixed a bug which has been open for some years .. however I don’t remember well and it was not easy to find though a search on mpm event lead me to this article somehow. The search was because of this strange behaviour.
I do linux full stack/sysadmin professionally for 15 years and another 5 years for fun by now and I never came across nothing like this.
I can not recommend mpm event for important setups where you do not have monitoring in place or recycle servers on schedule with others taking over meanwhile.
mpm_event can work great, though at the current state, don’t turn ya back on it.
Thanks for the heads up. I think I only have 1 or 2 Apache servers left but mpm_event was fine for me. If you ever do find out what it was, please come back and comment. 🙂
Hi, sorry, took me a while.
Did a mpm_worker setup and one of the servers behind load balancer managed to reproduce the error I had in mind.
ubuntu 20.04 Apache/2.4.46
is the bug description.
Despite the claim, I say it is not fixed.
others suspect this, aswell.
At the time of writing this article of cpanel is 3 months old, referring to the same apache 2.4.46 version and suggesting
1. Switching to MPM Prefork
2. Configuring logrotate to restart Apache instead of reloading it and increasing the MaxRequestWorkers limit