Thanks to Godfrey Cheng for the helpful information I have received from him so far. He pointed out to me that there is a Rack middleware that will provide me with a more accurate time for the entire Rails request in the X-Runtime HTTP header in the response compared to the reported time in the logs (completed in XXXms ...).
Here is what I get from my tests:
1 - Access the direct URL to the Rails action in Chrome:
- X-Runtime: 25ms
- Chrome timeout: 27ms
- Reporting time in Rails log format: Completed 200 OK in 7 ms (Views: 0.9ms | Continuation: 3.0ms)
2 - Access the same URL, but using nginx with proxy_pass, also in Chrome:
- X-Runtime: 84ms
- Chrome timeout: 88 ms
- Completed 200 OK in 7ms (Views: 0.8ms | Continued: 2.9ms)
3 - Copying the Curl address from the Chrome developer tool and launching it with curl -I:
- X-Runtime: 105 ms (sometimes up to 400 ms)
- Completed 200 OK in 88ms (Views: 2.0ms | Sequel: 5.5ms)
These timings are pretty much consistent when I try them many times.
Any ideas why Rails will take longer to serve the same request if it passes through nginx proxy_pass? I understand that Curl cannot take advantage of features like keep-alive, but I believe that nginx can take advantage of this. But in any case, the connection opening time should not be taken into account by the X-Runtime header, right?
source share