title: Why is request_time much larger than upstream_response_time in nginx access.log?
body: <p>I am trying to improve the performance of a web app. Profiling the app itself, I found its response time are quite acceptable (100ms-200ms), but when I use ApacheBench to test the app, the response time sometimes exceeds 1 second. When I looked closely at the logs, I found a big discrepancy between <code>request_time</code> and <code>upstream_response_time</code> occasionally:</p>
  
  <pre><code>"GET /wsq/p/12 HTTP/1.0" 200 114081 "-" "ApacheBench/2.3" 0.940 0.286
  "GET /wsq/p/31 HTTP/1.0" 200 114081 "-" "ApacheBench/2.3" 0.200 0.086
  </code></pre>
  
  <p>The <code>upstream_response_time</code> is quite close to my profiling in the web app, but <code>request_time</code> is close to one second for the first request.</p>
  
  <p>What could cause this discrepancy?</p>
  
  <p>I understand <code>request_time</code> is recorded from the first byte received to last response byte sent, it can be affected by network condition and client problem. I am wondering what should I do to reduce the average <code>request_time</code> as much as possible?</p>