Introduction
The Apache Multi-Processing Modules (MPMs) are a set of modules that control how Apache processes requests. The MPM that you choose plays a significant role on the performance and stability of your website.
In this article, we will discuss the four most popular MPMs: Prefork, Worker, Event, and Itk. We will explain the key benefits and drawbacks of each of these MPMs and what factors you should consider when choosing an MPM for your website.
MPM Prefork
The Prefork MPM is the default MPM for older versions of Apache than version 2.4 . It is a simple and reliable MPM that is well-suited for websites with low to moderate traffic.
Pros of the Apache Prefork MPM:
- Stability: The Prefork MPM is known for its stability, making it a good choice for servers that need to be up and running 24/7.
- Compatibility: The Prefork MPM is compatible with a wide range of software over other MPMs like Event or Worker, including some older and less well-maintained applications.
- Simplicity: The Prefork MPM is relatively easy to configure and manage.
Cons of the Apache Prefork MPM:
- Performance: The Prefork MPM is not as performant as Event & Worker MPMs, especially under high load.
- Memory usage: The Prefork MPM uses more memory than the Event & Worker MPMs, as it creates a separate full Apache process for each incoming connection.
- Scalability: The Prefork MPM is not as scalable as the Event & Worker MPMs, as it is limited by the number of processes that can be created on the system.
The Apache Prefork MPM is a good choice for servers that need to be stable and reliable, and that are running older or less well-maintained software. However, it is not as performant or scalable as the Worker MPM.
MPM Event
As of Apache 2.4, the Event MPM has taken over the mantle as the default MPM for Apache servers. The Apache Event MPM is a multi-processing module that uses a hybrid multi-threaded multi-process architecture to handle web requests. It is designed to be more scalable and efficient than the older MPMs, such as Prefork and Worker.
Pros of the Apache Event MPM:
- Scalability: The Event MPM can handle a large number of concurrent connections without consuming too much memory or CPU resources. This makes it a good choice for high-traffic websites and applications.
- Performance: The Event MPM is generally faster than the other MPMs, especially for dynamic content.
- Efficiency: The Event MPM uses fewer resources than the other MPMs, which can save money on hosting costs.
- Ease of use: The Event MPM is easy to configure and use. It is also compatible with most Apache modules.
Cons of the Apache Event MPM:
- Complexity: The Event MPM is more complex than the other MPMs, which can make it more difficult to troubleshoot problems.
- Compatibility: The Event MPM is not compatible with all Apache modules. Some modules may need to be patched or compiled with special options to work with the Event MPM.
- Memory usage: The Event MPM can use more memory than the Prefork MPM, especially when serving a large number of static files.
Overall, the Apache Event MPM is a good choice for most websites and applications. It is scalable, efficient, and easy to use. However, it is important to be aware of the potential drawbacks, such as complexity and compatibility issues.
MPM Worker
The predecessor to the Apache Event MPM, Worker MPM is also a hybrid multi-process multi-threaded server that uses multiple child processes with many threads each. Each thread handles one concurrent connection. The Worker MPM is more efficient than the Prefork MPM, as it can handle multiple requests with a single process. It is also a good choice for websites that use technologies such as mod_perl, as it can handle the high level of threading required by these technologies.
Pros of Apache Worker MPM:
- Better performance under high load: The Worker MPM can handle more requests per second than the Prefork MPM due to its multi-threaded design.
- Improved scalability: The Worker MPM can spawn new worker threads on-demand, which helps to improve scalability under high traffic conditions.
- Reduced memory usage: The Worker MPM uses less memory than the Prefork MPM, as it does not need to create a new process for each request.
- Support for non-thread-safe modules: The Worker MPM supports non-thread-safe modules, which is not possible with the Prefork MPM.
Cons of Apache Worker MPM:
- Increased complexity: The Worker MPM is more complex to configure and manage than the Prefork MPM.
- Potential for resource exhaustion: The Worker MPM can exhaust system resources if the number of worker threads is not properly configured.
- Compatibility issues: The Worker MPM may not be compatible with all Apache modules.
Overall, the Apache Worker MPM is a good choice for most websites and web applications. It offers better performance and scalability than the Prefork MPM, while still being relatively easy to manage. However, it is important to be aware of the potential for resource exhaustion and compatibility issues before using the Worker MPM
MPM ITK
The Apache Itk MPM (Multi-Processing Module) is a non-threaded MPM that allows you to run each of your vhost under a separate uid and gid. This means that the scripts and configuration files for one vhost no longer have to be readable for all the other vhosts.
Pros of Apache Itk MPM:
- Improved security: By running each vhost under a separate user account, you can reduce the risk of one vhost being compromised and affecting all the others.
- Increased stability: Since Itk is non-threaded, you can run non-thread-aware code without problems. This can help to improve the stability of your web server.
- Control: Itk gives you more control over how your web server handles requests. For example, you can specify the maximum number of processes that can be running for each vhost.
Cons: of Apache Itk MPM
- Performance: Itk can have a slight performance impact over other MPMs, such as Prefork and Worker. This is because Itk creates an extra fork per request.
- Complexity: Itk is more complex to configure than other MPMs. This is because you need to create a separate user account for each vhost.
- Compatibility: Itk is not compatible with all Apache modules. Be sure to check the compatibility of any modules you want to use before enabling Itk.
- Availability: Itk is not supported by all web hosting providers. Be sure to check with your provider before enabling Itk.
Overall, the Apache Itk MPM is a good choice for web servers that require high security and stability. However, it is important to be aware of the potential performance impact before using Itk.
Choosing the right Apache MPM
There are several choices for the right Apache MPM for your website. You will need to weigh the pros and cons outlined above to determine the best fit for your needs. Keep the following guidelines in mind when reviewing your options:
- If you are new to Apache, consider the Worker MPM. It is the best choice for most websites, and it is relatively easy to configure and manage.
- If you are running a high-traffic website, you may want to consider using the Event MPM. It is the most efficient MPM available, but it is also the most complex MPM to configure and manage.
- If you are running a high-traffic PHP website, you should consider the ITK MPM. It can improve security and performance for PHP websites over MPM Prefork.
- If you need to use modules that are not thread-safe, you will likely need to use the Prefork MPM. However, I recommend avoiding the Prefork MPM if possible, as it is the least efficient of all MPMs.
Conclusion
The MPM that you choose will have a significant impact on the performance and stability of your website. The factors that you should consider when choosing an MPM include the amount of traffic that your website receives, the stability of your website, and the resources available on your server. However, the type of website or application and the software technologies support for threaded processing are also big influencers when choosing an MPM.
I hope this article has helped you to understand the different MPMs available for Apache and how to choose the right MPM for your website.
Jason Potter is a Senior Linux Systems Administrator & Technical Writer with more than 20 years experience providing technical support to customers and has a passion for writing competent and thorough technical documentation at all skill levels.
Leave a Reply