title: Configuring HAProxy+nginx+PHP-FPM to out perform Apache+mod_php
body: <p><strong>Edit</strong></p>
  
  <p>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.</p>
  
  <p><strong>Original</strong></p>
  
  <p>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 .</p>
  
  <p>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.</p>
  
  <p>haproxy.cfg</p>
  
  <pre><code>global
          maxconn 4096
          user haproxy
          group haproxy
          daemon
          stats socket /var/run/haproxy.sock mode 0600 level admin
  
  defaults
          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 192.168.1.199:8080 check
  </code></pre>
  
  <p>nginx.conf</p>
  
  <pre><code>worker_processes 2;
  
  events {
          worker_connections 768;
  }
  </code></pre>
  
  <p>www.conf</p>
  
  <pre><code>pm = dynamic
  pm.max_children = 10
  pm.min_spare_servers = 2
  pm.max_spare_servers = 4
  pm.max_requests = 500
  </code></pre>
  
  <p>apache.conf</p>
  
  <pre><code>&lt;IfModule mpm_prefork_module&gt;
      StartServers          5
      MinSpareServers       5
      MaxSpareServers      10
      MaxClients           10
      MaxRequestsPerChild   0
  &lt;/IfModule&gt;
  &lt;IfModule mpm_worker_module&gt;
      StartServers          2
      MinSpareThreads      25
      MaxSpareThreads      75
      ThreadLimit          64
      ThreadsPerChild      25
      MaxClients           10
      MaxRequestsPerChild   0
  &lt;/IfModule&gt;
  &lt;IfModule mpm_event_module&gt;
      StartServers          2
      MinSpareThreads      25
      MaxSpareThreads      75
      ThreadLimit          64
      ThreadsPerChild      25
      MaxClients           10
      MaxRequestsPerChild   0
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>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?</p>