Configuring HAProxy+nginx+PHP-FPM to out perform Apache+mod_php



Running my OS on the VirtualBox was the issue. As soon as I made my OS the native on the disk, I was able to see the performance boost.


I've read a lot of people recommend ditching Apache+mod_php for HAProxy+nginx+PHP-FPM. I'm trying to verify that it's a more efficient setup, but am not seeing the results people describe. Both siege and ab (Apache Benchmark) are showing that Apache at any number of concurrent connections is giving better responses per second, and can support more connections .

I'm running Ubuntu 11.04 server on VirtualBox. It has 10 gigs of space, and 1,344 megs of memory. I used apt-get for installing the programs mentioned above. Here are the related config files with just the important parts included.


        maxconn 4096
        user haproxy
        group haproxy
        stats socket /var/run/haproxy.sock mode 0600 level admin

        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option  redispatch
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen tcpcluster *:80
        mode tcp
        option tcplog
        balance roundrobin

        server tcp01 check


worker_processes 2;

events {
        worker_connections 768;


pm = dynamic
pm.max_children = 10
pm.min_spare_servers = 2
pm.max_spare_servers = 4
pm.max_requests = 500


<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients           10
    MaxRequestsPerChild   0
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients           10
    MaxRequestsPerChild   0
<IfModule mpm_event_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients           10
    MaxRequestsPerChild   0

Given that PHP-FPM and Apache both have a maximum of 10 children, I would expect that any speed advantage would be visible. In every test I've run (always waiting until load is 0.01 before I run the test), Apache is always able to handle more request more efficiently.

Is there some other optimization that can be made so that the setup best suited to scale will outperform the setup that should not be more efficient?




Use haproxy as a connection concentrator : use "mode http" instead of "mode tcp", use "option http-server-close" and set a server maxconn value well below the worker connections value. You should cross a point where the lower concurrency brings much more performance with much lower RAM usage and better cache efficiency along the whole chain.

BTW, what are the numbers we're talking about ? Do they measure in hundreds or in thousands of requests per second ? Because clearly, the application server will make a real difference only in the higher loads. Obviously if the application runs very slowly, there is no reason to see a difference when replacing the server.

People are also looking for solutions to the problem: Sending form with a large amount of values in PHP


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.