Apache event MPM Redirected from Components/Apache/Apache MPM event

    What is the Apache event MPM?

    Apache supports three different Multi-Processing Modules (MPMs) that are responsible for binding to network ports on the machine, accepting requests, and dispatching children to handle the requests.

    - Prefork: each child process handles one connection at a time. This is the default mode for Apache.

    - Worker: It uses multiple child processes with many threads each. 

    - Event: This MPM was designed to allow more requests to be served simultaneously by passing off some processing work to supporting threads and freeing up the main threads to work on new requests.


    Bitnami stacks ship all the different Multi-Processing Modules (MPMs) shared modules so it is possible to configure Apache to enable any of them. The default configuration could be different depending on what you are currently using:

    - Native installers: They are configured for development purposes. Apache is configured to use prefork mode. PHP applications are configured to use "mod_php". If you use a native installer and you want to modify your configuration, check our guide to know how to enable Apache MPM event and PHP-FPM manually.

    - Virtual machines and Cloud Images: They are configured for running in production environments by default. Apache is configured to use the event mode and PHP applications will use PHP-FPM server for the requests.

    What is PHP-FPM?

    PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for heavy-loaded sites. It has been bundled with PHP since version 5.3.3. PHP-FPM has the ability to start workers with different environments and to manage these processes. You can find more PHP-FPM features here

    The recommended configuration is to configure Apache to serve the static files requests (images, css, javascripts and more) and use PHP_FPM with Apache "mod_proxy" module to handle the PHP requests.

    Why MPM event and PHP-FPM is recommended for production?

    The default configuration for Apache and PHP in Linux systems is to use the prefork MPM with an embedded PHP interpreter. This is a very robust configuration but it means that Apache needs to spawn a separate process for every simultaneous request it wants to serve. Because every child process loads a PHP interpreter and associated libraries, this configuration takes a significant amount of memory. In addition to this, a whole process is tied up when waiting for requests when browsers open a persistent connection to the server (which is particularly common with AJAX-heavy web applications.)

    On high traffic websites, an alternate MPM (the event MPM) is preferable because it has the ability to serve a large amount of requests while maintaining low memory usage. It does so by using threads to serve requests. It retains some of the stability of a process-based server by keeping multiple processes available, each with many threads so a thread potentially misbehaving would only affect all the other threads in the same process.

    Additionally, the event MPM uses a dedicated thread to deal with the kept-alive connections, and hands requests down to child threads only when a request has actually been made. That allows those threads to free back up immediately after the request is completed.

    Because PHP is not thread-safe on Unix environments (in particular many of its most popular extensions), it is not possible to embed an interpreter in each event MPM process. It needs to live as a separate PHP-FPM process. Apache will serve all static resources (images, CSS, etc.) directly while PHP-FPM serves the PHP-related requests.

    In the examples below we provide some benchmarks. We used two different Amazon EC2 instances (micro and small) to run our tests. Both instances had the same WordPress installation and the same memory settings. We use the Siege tool in our tests that is an HTTP load testing and benchmarking utility. We also use the webpagetest.org tool that  allows you to run speed test from multiple locations using real browsers.


    The test below uses the Siege tool to do a request to the WordPress web page and all the static files. We use 30 concurrent users for 1 minute and we got the following results:


    Small EC2 instance with MPM prefork and "mod_php"

    Used memory (Apache):        525MB

    Transactions:        1606 hits
    Availability:       89.92 %
    Elapsed time:       59.08 secs
    Data transferred:       12.49 MB
    Response time:        0.89 secs
    Transaction rate:       27.18 trans/sec
    Throughput:        0.21 MB/sec
    Concurrency:       24.28
    Successful transactions:        1411
    Failed transactions:         180
    Longest transaction:        5.89
    Shortest transaction:        0.11

    Small EC2 instance with MPM event and PHP-FPM

    Used memory (Apache + PHP-FPM):        78MB + 200MB (max)

    Transactions:        2480 hits
    Availability:       91.75 %
    Elapsed time:       59.10 secs
    Data transferred:       21.30 MB
    Response time:        0.69 secs
    Transaction rate:       41.96 trans/sec
    Throughput:        0.36 MB/sec
    Concurrency:       29.11
    Successful transactions:        2480
    Failed transactions:         223
    Longest transaction:        6.17
    Shortest transaction:        0.11


    The main differences are the following:

    • The used memory is much lower.
    • The amount of data transferred is much higher.
    • The transaction rate is higher and there are less failed transactions.


    The next test shows the connection and page serving times of running 9 concurrent users using EC2 micro instances with the same WordPress sample site.

    1. Apache MPM prefork with "mod_php"



    2. Apache MPM event with PHP-FPM



    The main differences are the following:

    • The load time is much lower in the second case. It is also important that the load time in the first case could be very different  for different tests, it depends on the number of free child processes.
    • The "time to first byte" is much lower in the second case.


    The previous test only have 11 static files but in a production-running PHP application it is usual to have more and bigger static files. The following example shows a simple static HTML page with 240 small png images. We use the Siege tool with 30 concurrent users during 30 seconds.


    Small EC2 instance with MPM prefork

    Used Memory:         182MB

    Transactions:        2148 hits

    Availability:       98.90 %
    Elapsed time:       29.38 secs
    Data transferred:        1.10 MB
    Response time:        0.25 secs
    Transaction rate:       73.11 trans/sec
    Throughput:        0.04 MB/sec
    Concurrency:       18.32
    Successful transactions:        2148
    Failed transactions:          24
    Longest transaction:       10.55
    Shortest transaction:        0.11

    Small EC2 instance with MPM event

    Used Memory:        66MB

    Transactions:        3568 hits

    Availability:      100.00 %
    Elapsed time:       29.23 secs
    Data transferred:        1.82 MB
    Response time:        0.24 secs
    Transaction rate:      122.07 trans/sec
    Throughput:        0.06 MB/sec
    Concurrency:       29.41
    Successful transactions:        3568
    Failed transactions:           0
    Longest transaction:        0.94
    Shortest transaction:        0.11


    The main differences are the following:

    • The used memory is much lower in the second case.
    • The Transaction rate is much higher in the second case.
    • The Longest transaction is similar to the Shortest transaction. 


    In conclusion, Apache event MPM increases the performance of your Apache, allowing it to serve more requests with less memory. If you want to deploy a PHP application you should use PHP-FPM to handle PHP requests. This is highly recommend for running applications in servers with limited memory, such as like cloud Instances with 512MB or 1Gb RAM.

    Bitnami stacks uses this configuration by default for Virtual Machines and Cloud Images.

    Tag page (Edit tags)
    • No tags
    Page statistics
    21177 view(s), 15 edit(s) and 10527 character(s)


    You must login to post a comment.