Nginx - request_time和upstream_response_time的区别
request_time
官網(wǎng)描述: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。
指的就是從接受用戶請(qǐng)求的第一個(gè)字節(jié)到發(fā)送完響應(yīng)數(shù)據(jù)的時(shí)間,即$request_time包括接收客戶端請(qǐng)求數(shù)據(jù)的時(shí)間、后端程序響應(yīng)的時(shí)間、發(fā)送響應(yīng)數(shù)據(jù)給客戶端的時(shí)間(不包含寫日志的時(shí)間)。
官方文檔:http://nginx.org/en/docs/http/ngx_http_log_module.html
upstream_response_time
官網(wǎng)描述: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向后端建立連接開始到接受完數(shù)據(jù)然后關(guān)閉連接為止的時(shí)間。
從上面的描述可以看出,$request_time肯定比$upstream_response_time值大;尤其是在客戶端采用POST方式提交較大的數(shù)據(jù),響應(yīng)體比較大的時(shí)候。在客戶端網(wǎng)絡(luò)條件差的時(shí)候,$request_time還會(huì)被放大。
官方文檔:http://nginx.org/en/docs/http/ngx_http_upstream_module.html
“other” times
除了上述的request_time和upstream_response_time比較常用,在新的Nginx版本中對(duì)整個(gè)請(qǐng)求各個(gè)處理階段的耗時(shí)做了近一步的細(xì)分:
$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建立連接的時(shí)間,如果是到后端使用了加密的協(xié)議,該時(shí)間將包括握手的時(shí)間。
$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響應(yīng)頭的時(shí)間。
指導(dǎo)意義
所以在通過nginx的access_log來分析后端程序接口響應(yīng)的時(shí)候,需要在nginx的log_format中添加$upstream_response_time字段。
?
總結(jié)
以上是生活随笔為你收集整理的Nginx - request_time和upstream_response_time的区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java NIO学习系列七:Path、F
- 下一篇: Nginx重启时丢失nginx.pid文