Introduction to the Apache Multiplex module (MPMS) _linux

Source: Internet
Author: User

When the whole world is slowly leaning toward Nginx, if you are still using Apache, then you may be able to do whatever it takes to keep pace. You may adjust the modules to be loaded, using keepalive, fiddling with the Content negotiation module (mod_negotiation, selecting a document that best matches the client's requirements from several documents), The followsymlinks directive allows soft links to be used in this directory and overrides functionality; You might even put more hardware into it and pretend you don't. However, if you are running a site that is so busy that you don't want to crash the site for memory reasons, then you should focus on the MPM you're using.

MPM, also known as the multi-channel processing module (Multi processing module), is related to the entire HTTP session. From listening on the web, requesting access to the most important-how to handle the child request, here we discuss the subprocess and child threads. For UNIX system machines, Apache offers 3 kinds of MPM to choose from:; Prefork, Worker, and Event. At the same time, there are many other kinds of MPM for other systems, but we focus on the most common, perhaps the most important thing you want to see. These MPM handle processes and potential threads that the Apache server uses to accept, process, and server HTTP requests.

The process is an instance of a program from a less rigorous standpoint. Each process is fully self-contained and is performed completely independently of the address space, variables, memory, and other processes. To understand the purpose and content of this article, you can think about the following sentence: 5 Apache processes represent 5 different Apache instances running. While this is a fairly alarming practice, it is safe enough to remember the purpose of this article.

In other words, a thread is created and owned by a process. A process can have multiple threads, and these threads are not completely independent. They share the same state and address space that the process assigns to them.

In short, a process is an instance of a program that is used to tell the entire system that it exists and that it needs resources and that it can execute its own resources; As a result, threads do not need to publish themselves but are made by the entire application such as processes, and threads essentially use less system resources such as memory.

Apache prefork MPM

Prefork multi-processing modules are non threading. It does not use threads at all, and uses the entire process to process each HTTP request. When an HTTP request is passed in, assuming it is used to request you to add a picture of the cat, the whole process will go to the request bundle and be responsible for the person's request. If there are other people at the same time browsing the pictures of your cat, another completely different process will be used.

Prefork is very good in terms of speed and stability. Prefork only a slight edge response time, this is because it does not need to handle different threads in its process, and it is stable when a particular request is wrong, because the whole process is only determined by one request, and other requests are handled by another process, so other requests are unaffected.

Prefork also applies if you are using an Apache module that cannot handle threads. The most common is the mod_php module (although its latest effort is in the direction of Zts). You may experience this problem with PHP and/or some scripts that you can't handle with Apache, but there are some exceptions like php-fpm.
However, if you need to deal with a large number of concurrent requests, this approach will be crazy to "eat" system resources. Note that each process will publish itself as a complete Apache instance. This means that it loads all the modules and is a complete Web server for each request. If the number of requests is very large, and because the coordinator needs to publish processes that are the same as the number of requests to process these requests, this quickly forces the memory usage to reach the limit.

Apache Worker MPM

The work multiplexing module uses threads, which are well handled in terms of memory usage in high concurrency. In a multiplexing module, fewer processes are required because it does not want Prefork to create a process for each request, the worker mode creates a thread in the process, and the incoming connection is processed by a different thread in a process. In worker mode, new connections only need to wait for idle threads, rather than waiting for idle processes as in prefork.

Apache Event MPM

The event pattern is very new. In fact, it was released as a stable version only in the Apache2.4 version. Event mode works the same way as worker mode, and it also uses processes and threads. Their biggest difference is that the event mode creates a thread for each request instead of creating a thread for an HTTP connection.
There is a situation where you like to use threads but there is an application where the application uses a longer keepalive timeout when this pattern works. In worker mpm, threads are bound to the connection and remain occupied regardless of whether the HTTP request is handled or not.

In event MPM, if the thread that handles the connection is only used to process the current request and is released immediately after the request processing completes, regardless of the HTTP connection being processed by the parent process. At the same time, the thread can be used to process other requests after the request has been processed for immediate release. This means that fewer threads are needed!

What do I do with this information?

So, which one should you use? In my opinion, with my most loyal advice, everyone should use worker MPM, because it is very good at concurrency and uses less RAM memory, although if there is a problem with compatibility, you may need to switch back to Prefork.

If you are using the latest version of Apache, you can try to use the event MPM.

If you are using PHP, you must use the PHP-FPM when using worker mpm or event mpm. If you use mod_php in worker mode then your application may make mistakes in one of these or that form. In fact, you should probably use the PHP-FPM, regardless of the MPM mode of Apache.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.