Quantcast
Viewing all articles
Browse latest Browse all 31

Apache MPM: Which One To Use?

I’ve been using Apache with different Apache MPM (multi-processing module) configurations for some time now. I use Worker in most of my Apache environments, but there are circumstances where Prefork or Event may be preferable. Here’s a summary of their strengths and weaknesses.

Apache MPM #1: Prefork

Apache Prefork is the default in most installs, and it’s the safest and most compatible choice. Prefork uses server processes to create child processes for intercepting incoming requests, and each child process handles one request at a time. Because its server processes sit and wait for incoming traffic, Prefork is faster than threaded MPMs when handling one request at a time, but concurrent requests can be slow because they have to wait until a server process is free. Prefork also uses a lot of memory as the number of child processes increase.

In most environments, concurrency is going to be more important than speed in handling single requests. You should only use Prefork if you’re running a module that isn’t safe with threaded MPMs like Worker or Event (e.g., mod_php). But even then I’d use Worker with PHP-FPM and FastCGI.

Apache MPM #2: Worker

Worker uses threading, making it a better choice than Prefork for most current web servers. Worker spins off a specified number of child processes, which in turn spin off child threads, and Worker tries to keep some spare threads available to handle incoming connections. Since free threads are usually available, while Prefork’s servers often aren’t, Worker can handle many more concurrent requests than Prefork. Its reliance on threading is also much lighter on memory consumption.

I’d always use Worker unless you need Prefork for compatibility or you’re running Apache 2.4. And if you are running Apache 2.4, consider…

Apache MPM #3: Event

The Event MPM is considered stable as of Apache 2.4 but experimental on earlier versions. It’s similar to Worker but it addresses the problem of kept-alive connections: when a client makes its first request to the web server, and then uses keep-alive to keep the connection open, Event passes these kept-alive connections to a separate dedicated thread to free up its main threads for more incoming requests. This is great for concurrency since you’re often dealing with clients that aren’t necessarily all active at once and may have long keep-alive timeouts.

The exception is with SSL connections, in which case Event behaves just like Worker, locking a given connection to a given thread until the connection closes.

I wouldn’t use Event only if it’s considered unstable on your Apache installation (i.e., less than version 2.4) or you need Prefork for compatibility.

In general you always need to consider the role of your web server. Most of the compatibility issues addressed by Prefork can be worked around while high concurrency is better suited to modern web clients and scaling. Nevertheless, if you’re serving primarily PHP to relatively few concurrent connections, Prefork may be preferable to the threaded MPMs.

The post Apache MPM: Which One To Use? appeared first on GeoffStratton.com.


Viewing all articles
Browse latest Browse all 31

Trending Articles