Nginx - request_time和upstream_response_time的区别
request_time
官網描述:request processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client。
指的就是從接受用戶請求的第一個字節到發送完響應數據的時間,即$request_time包括接收客戶端請求數據的時間、后端程序響應的時間、發送響應數據給客戶端的時間(不包含寫日志的時間)。
官方文檔:http://nginx.org/en/docs/http/ngx_http_log_module.html
upstream_response_time
官網描述:keeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution. Times of several responses are separated by commas and colons like addresses in the?$upstream_addr?variable.。
是指從Nginx向后端建立連接開始到接受完數據然后關閉連接為止的時間。
從上面的描述可以看出,$request_time肯定比$upstream_response_time值大;尤其是在客戶端采用POST方式提交較大的數據,響應體比較大的時候。在客戶端網絡條件差的時候,$request_time還會被放大。
官方文檔:http://nginx.org/en/docs/http/ngx_http_upstream_module.html
“other” times
除了上述的request_time和upstream_response_time比較常用,在新的Nginx版本中對整個請求各個處理階段的耗時做了近一步的細分:
$upstream_connect_time(1.9.1):
keeps time spent on establishing a connection with the upstream server (1.9.1); the time is kept in seconds with millisecond resolution. In case of SSL, includes time spent on handshake. Times of several connections are separated by commas and colons like addresses in the $upstream_addr variable.
跟后端server建立連接的時間,如果是到后端使用了加密的協議,該時間將包括握手的時間。
$upstream_header_time(1.7.10):
keeps time spent on receiving the response header from the upstream server (1.7.10); the time is kept in seconds with millisecond resolution. Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.
接收后端server響應頭的時間。
指導意義
所以在通過nginx的access_log來分析后端程序接口響應的時候,需要在nginx的log_format中添加$upstream_response_time字段。
?
總結
以上是生活随笔為你收集整理的Nginx - request_time和upstream_response_time的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java NIO学习系列七:Path、F
- 下一篇: MySQL的limit用法和分页查询的性