title: Nginx Fastcgi_cache performance - Disk cached VS tmpfs cached VS static file
body: <p>Two warnings: this performance thing is addictive. Every bit you squeeze, you want more.
  And English is my second language so pardon me for any mistakes.</p>
  
  <p>Anyways I am comparing nginx performance for wordpress websites in different scenarios and something seems weird. So I am here to share with you guys and maybe adjust my expectations.</p>
  
  <pre><code>Software                                                                            
  #       NGINX 1.4.2-1~dotdeb.1                                                          
  #       PHP5-CGI 5.4.20-1~dotdeb.1                                                      
  #       PHP-FPM 5.4.20-1~dotdeb.1                                                       
  #       MYSQL Server 5.5.31+dfsg-0+wheezy1                                              
  #       MYSQL Tuner 1.2.0-1                                                             
  #       APC opcode 3.1.13-1 
  </code></pre>
  
  <p>This is a ec2 small instance.
  All tests done using SIEGE 40 concurrent requests for 2 minutes.
  All tests done from localhost > localhost.</p>
  
  <p><strong>Scenario one - A url cached via fastcgi_cache to TMPFS (MEMORY)</strong><br>
  SIEGE -c 40 -b -t120s '<a href="http://www.joaodedeus.com.br/quero-visitar/abadiania-go">http://www.joaodedeus.com.br/quero-visitar/abadiania-go</a>'</p>
  
  <pre><code>Transactions:                    1403 hits
  Availability:                 100.00 %
  Elapsed time:                 119.46 secs
  Data transferred:              14.80 MB
  Response time:                  3.36 secs
  Transaction rate:              11.74 trans/sec
  Throughput:                     0.12 MB/sec
  Concurrency:                   39.42
  Successful transactions:        1403
  Failed transactions:               0
  Longest transaction:            4.43
  Shortest transaction:           1.38
  </code></pre>
  
  <p><strong>Scenario two - Same url cached via fastcgi_cache to disk (ec2 oninstance storage - ephemeral)</strong> </p>
  
  <pre><code>Transactions:                    1407 hits
  Availability:                 100.00 %
  Elapsed time:                 119.13 secs
  Data transferred:              14.84 MB
  Response time:                  3.33 secs
  Transaction rate:              11.81 trans/sec
  Throughput:                     0.12 MB/sec
  Concurrency:                   39.34
  Successful transactions:        1407
  Failed transactions:               0
  Longest transaction:            4.40
  Shortest transaction:           0.88
  </code></pre>
  
  <p><strong>Here is where the first question pops in. I dont see a huge difference on ram to disk. Is that normal? I mean, no huge benefit on using ram cache.</strong></p>
  
  <p><strong>Scenario three - The same page, saved as .html and server by nginx</strong> </p>
  
  <pre><code>Transactions:                    1799 hits
  Availability:                 100.00 %
  Elapsed time:                 120.00 secs
  Data transferred:              25.33 MB
  Response time:                  2.65 secs
  Transaction rate:              14.99 trans/sec
  Throughput:                     0.21 MB/sec
  Concurrency:                   39.66
  Successful transactions:        1799
  Failed transactions:               0
  Longest transaction:            5.21
  Shortest transaction:           1.30
  </code></pre>
  
  <p>Here is the main question. This is a huge difference. I mean, AFAIK serving from cache is supposed to be as fast as serving a static .html file, right? I mean - nginx sees that there is a cache rule for location and sees that there is a cached version, serves it. Why so much difference?</p>
  
  <p><strong>Cache is working fine</strong></p>
  
  <pre><code>    35449 -
    10835 HIT
     1156 MISS
     1074 BYPASS
      100 EXPIRED
  </code></pre>
  
  <p>Best regards.</p>