title: Finding an HTTP bottleneck
body: <p>I'm developing a custom Blog application in Ruby on Rails, having load speed as a primary measure of success.</p>
  
  <p>I'm caching (with Redis) both views and models to shorten up queries and rendering of raw HTML. Finally I succeeded loading a single post in under 15ms. Time to deploy.</p>
  
  <p>I bought a Linode 20$/month machine with 2gb ram, 2 cores, ssd storage, 40gbit in, 250mbit out. The machine is hosted in London. I installed Ubuntu 15.04.</p>
  
  <p>I set up Cloudflare free plan for more aggressive caching and minification of assets. I enabled the Full SSL functionality.</p>
  
  <p>I installed nginx as a proxy to the Rails application running on Unicorn. Rails, Redis, PostgreSQL and nginx run on the same server.</p>
  
  <p>I am in Rome, Italy. The nearest Cloudflare datacenter is in Milan, while the origin Linode server is in London. The average request time (as reported by the chrome network panel) is 230ms. Whops...</p>
  
  <p>So first of all I checked out the Rails logs, and the log reported times (and the X-Runtime header) where consistent with my development data (&lt; 20ms).</p>
  
  <p>I edited nginx configuration to add an X-Time header:</p>
  
  <pre><code>add_header X-Time $request_time;
  </code></pre>
  
  <p>And that shows just a few ms over the Rails timings.</p>
  
  <p>Then I enabled direct access to the server (disabled Cloudflare) and disabled SSL to remove the handshake overhead.</p>
  
  <p>So I finally found that with or without Cloudflare, with or without SSL, load times where always quite random in the range [180-350]ms, with no apparent explaination.</p>
  
  <p>Here's a shot of the Chrome timing panel, without both Cloudflare and SSL. Just a raw HTTP connection directly on port 80 of the nginx server.</p>
  
  <p><img src="https://i.stack.imgur.com/viv0K.png" alt="Chrome timing panel"></p>
  
  <p>Why am I seeing such high times on a blazing fast application? What should I check next? Is the Linode server my bottleneck?</p>
  
  <p>Thanks</p>
  
  <h2>Edit</h2>
  
  <p>It looks like gzip compression as enabled by default by nginx was slowing the whole thing down by a 30%. I have now disabled it since Cloudflare will gzip it anyway in a second step. Now request times are between 120 and 200ms but I still feel like it could be improved.</p>