What is Apache MPM (Multi-Processing Modules) and How They Work

What is Apache MPM (Multi-Processing Modules) and How They Work. The majority of Linux system administrators begin with Apache as they learn the operating system because it is the most widely used web server for Linux web servers. However, many people are unaware of how Apache functions, including how it manages incoming connections and many processes.

The performance of the Apache server as a whole is influenced by the kind of multi-processing module (MPM) you have. Since MPMs are used by all Apache versions 2.0 and higher, there exist different MPMs for different operating systems. This article will introduce you to Apache, its Multi-processing modules, and how they work.

Let’s start with What is Apache MPM (Multi-Processing Modules) and How They Work.

What are Multi-processing Modules

A multi processing module is a package that allows the creation of processes using an API similar to the threading module. This package provides both local and distant concurrency by employing subprocesses rather than threads, thereby avoiding the Global Interpreter Lock. As a result, the multiprocessing module enables the programmer to utilize various processors on a particular machine fully.

Additionally, the multiprocessing module introduces APIs for which there is no equivalent in the threading module. An example is a pool object, which provides a practical method of parallelizing the execution of a function across multiple input values and distributes the input data across processes. It can be run on both Windows and Unix.

What are Apache Multi-Processing Modules?

The modular design of the Apache web server contributes to its global dominance. With Multi-Processing Modules, or MPMs, were added to Apache 2 and alter the web server’s fundamental operation. Moreover MPM handles a number of significant activities, such as responding to requests and starting new threads or child processes. It does this by altering Apache’s network behaviour which includes listening, request acceptance and handling.

How Do Multi-Processing Modules Work?

As an essential component of Apache is MPM that manages operations, including establishing network connections (binding to ports), monitoring and accepting client requests (from browsers). Also it is spawning threads or child processes to perform the requests. Only one MPM can be loaded at a time due to the requirement that these essential functions be completed consistently for each request. The simultaneous installation of more than one MPM is prohibited by EasyApache 4.

General control of Apache’s  is then handed off to a process management module, or MPM.At the conclusion of the start up step. As an interface between the operating system and the Apache server, MPM’s primary function is to optimize Apache for the platform on which the server is running. Understanding threading and forking are crucial to comprehend how the different MPMs operate.

Threading and Forking

A server creates a connection and serves the content when someone views a web page. Without forking or starting threads, this could be accomplished ineffectively. Making forks, which allow Apache to manage numerous connections at once, is one way it can handle requests more effectively. These forks are separate from the parent process and have their own state and memory.

Therefore, when more children are formed, Apache uses more resources. Threads are useful in this situation. A thread is a smaller process that shares its parent’s memory and state. Since threads consume less memory than forked processes, they are also effective.

Multi-Processing Modules and Their Working Principle

Worker MPM

Worker MPM of Apache becomes a multi process and multi threaded web server. The system makes use of a parent process that forks off child processes as required. The child processes then create a fixed (but variable) number of threads and a listener thread. The listener thread listens for new connections. 

Additionally Apache can process many requests while utilizing only a small amount of system resources since the MPM employs threads.  A worker typically advises for high-traffic servers running Apache versions earlier than 2.4. However, Worker is incompatible with libraries that are not thread-safe. Due to this, Worker MPM is a solid choice for servers that handle a lot of traffic.

Event MPM

Event MPM adds better keep alive handling to the worker MPM. For each process, a listener thread is used to manage live connections. A child process reports to the listener process when it has completed its task and becomes available for additional tasks. When the KeepAliveTimeout has expired, the listener process is killed. Then the listener passes the job at hand to the first available listener if there are any further connections.

Prefork MPM

Prefork is the default MPM on cPanel servers. This web server is referred to as pre forking. Takes advantage of a parent process to make an effort to keep a number of extra or idle processes open to accommodate fresh requests. Since the prefork MPM is not threaded, only one request is processed by each child at once.

It’s crucial to strike the correct balance between the maximum number of processes and the available RAM on a pre-forking server because it consumes a lot of RAM. Meanwhile prefork must always be used whenever something that isn’t thread-safe needs to run.

MPM ITK

The last Apache module that is dependent on the prefork MPM is MPM ITK. Module is made to address the problem of privilege separation, which is unavoidable. The nobody user, who essentially has the fewest privileges, runs as the Apache parent process by default. However, the group ownership is problematic because it doesn’t distinguish between several server accounts. 

When the module is activated, Apache reads the request headers as root rather than the nobody user and then changes to the user before processing the request. The module must be used with the CGI handler and has a performance cost. The process is over once that has been accomplished.

Choosing an MPM

Choosing MPM must be selected and compiled into the server during configuration. Compilers can optimize numerous functions if threads are employed, but only if they are aware of the use of threads. To choose an MPM, use the configure script “mpm=NAME parameter” to select the desired MPM where the name of the desired MPM is NAME. 

Using “./httpd -l” once the server has been constructed will reveal which MPM was selected. Every module compiled into the server, including the MPM, will be listed by this command.

Changing the MPM

EasyApache is the fastest and safest method for changing the MPM. You can utilize the command line, but you must exercise caution because certain packages require both removal and installation to be done in one operation. The cPanel manual provides further details about altering the MPM. 

What is Apache MPM (Multi-Processing Modules) and How They Work Conclusion

What is Apache MPM

Various experimental MPMs are also available, but we do not advise using them in a real-world setting. Since they are experimental, there are no assurances that they will perform as anticipated. Hence, it is best to utilize them in a test setting. This way, you can make any necessary changes if they don’t work as well. Regardless, looking through the article, you can note that for every Apache server, there’s a befitting MPM for it.

Why don’t you check out more Apache content here

Avatar for Kamso Oguejiofor
Kamso Oguejiofor

Kamso is a mechanical engineer and writer with a strong interest in anything related to technology. He has over 2 years of experience writing on topics like cyber security, network security, and information security. When he’s not studying or writing, he likes to play basketball, work out, and binge watch anime and drama series.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x