Understanding Apache’s Three MPM Modes: Prefork, Worker, and Event
Apache offers three core Multi-Processing Modules—prefork, worker, and event—each with distinct process/thread models, memory usage, and suitability for high-concurrency scenarios, and this article explains how they work, their trade-offs, and why event MPM is the most memory-efficient choice.
Prefork MPM (multi‑process mode)
Apache first creates a master process that performs initialization, then forks a pool of child processes that inherit the master’s memory space. These processes wait for requests, reducing the overhead of repeatedly creating and destroying processes.
The advantage is isolation: each process has its own memory, so a crash in one does not affect others. However, each child consumes a full copy of the memory, leading to significant duplication and limiting the total number of processes. In high‑concurrency environments with many keep‑alive connections, these processes can become exhausted, making prefork unsuitable for such scenarios.
Worker MPM (mixed process‑thread mode)
Worker uses a small number of preforked processes, each spawning multiple threads. Each incoming request is handled by a thread, which shares the parent process’s memory, reducing overall memory consumption compared to prefork.
Although memory usage improves, keep‑alive connections still occupy threads, and thread safety becomes a concern because multiple threads access shared resources, potentially causing instability. Additionally, if a thread crashes, it can affect other threads within the same process.
Event MPM (mixed process‑thread mode with epoll)
Available and stable since Apache 2.4, event MPM is similar to worker but adds a dedicated thread to manage keep‑alive connections. When a real request arrives, the connection is handed off to a worker thread; after processing, the thread is released.
This design eliminates the waste of threads that are idle yet hold connections, improving request handling under high concurrency and reducing memory usage because fewer idle threads remain.
In practice, among Apache’s three modes, event MPM provides the best memory efficiency for real‑world applications.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
