Get the App
SLTechnology News&Howtos  ›  Servers  › 

Three MPM modes of Apache

Shulou Source: shulou.com Published: 2022-06-02 07:41:00 09月15日 Update

Apache prefork model:

Pre-derived mode, there is a main control process, and then generate multiple child processes, using the select model, the maximum concurrency of 1024, each child process has an independent thread to respond to user requests, relatively occupied memory, but relatively stable, you can set the maximum and minimum number of processes, is the oldest mode, but also the most stable mode, suitable for access is not very large scenes. Advantages: Stable Disadvantages: A large number of users access slowly, occupying resources, 1024 processes are not suitable for high concurrency scenarios

Apache Woker Model:

A multi-process and multi-threaded hybrid model, there is a control process, start multiple child processes, each child process contains fixed threads, use threads to process requests, when the thread is not enough to use a new child process, and then start threads inside the process to process requests, because it uses threads to process requests, so it can withstand higher concurrency. Advantages: Compared to prefork, it takes less memory and can handle more requests at the same time. Missing points: With keepalive's long connection mode, a thread will always be occupied, even if there is no data transfer, it will have to wait until the timeout is released. If too many threads are occupied in this way, it will also result in no service threads available in high concurrency scenarios. (This problem occurs in prefork mode.)

Apache event model:

Apache's latest pattern, apache 2.4.X series released in 2012 officially supports the event model, belongs to the event-driven model (epoll), each process responds to multiple requests, in the current version is already stable and available pattern. It is very similar to the worker pattern, the biggest difference is that it solves the problem of resource waste of threads that have been occupied for a long time in the keepalive scenario (some threads are hanging there because they are keepalive, almost no requests come in the middle, and even wait until timeout). In event MPM, there will be a dedicated thread to manage these keepalive threads. When there is a real request, the request will be passed to the service thread, and after execution, it will be allowed to release. This enhances request handling in high concurrency scenarios. Advantages: Single thread responds to multiple requests, occupies less memory, performs better under high concurrency, there will be a dedicated thread to manage keep-alive threads, when there is a real request, the request will be passed to the service thread, after execution, it is allowed to release Disadvantages: No thread safety control

Tags: Threads processes patterns models scenarios processing maximum size advantages memory time services multiple users shortcomings resources problems control management excellence Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Xiaomi Linux Microsoft MySQL