一、前言
这个主要是日志模块的延伸,这两个参数,在实战中非常重要,因此提出来单独说。
二、图解
从上图中得出以下结论:
- 打印日志是在最后一个步骤,也就是说整套请求完毕后,进行打印
- 请求的整套时间线:
1、客户端-----request---->nginx 2、nginx------connect---->服务端 3、服务端-----connect success---->nginx 4、nginx------send data----->服务端 5、服务端------response begin----->nginx 6、服务端------response end ------->nginx 7、nginx------response----->客户端 8、nginx记录日志 - 服务端运行时间=$upstream_header_time - $upstream_connect_time
- upstream_response_time:从nginx请求到响应结束的时间
- $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包括接收客户端请求数据的时间、后端程序响应的时间、发送响应数据给客户端的时间(包含写日志的时间)。
- 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向后端建立连接开始到接受完数据然后关闭连接为止的时间。
从上面的描述可以看出,
r
e
q
u
e
s
t
t
i
m
e
肯
定
比
request_time肯定比
requestt?ime肯定比upstream_response_time值大;尤其是在客户端采用POST方式提交较大的数据,响应体比较大的时候。在客户端网络条件差的时候,$request_time还会被放大。
- $upstream_connect_time
单位为秒。
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
单位为秒。
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响应头的时间。
总结:
所以我建议上述列出来的那些值,都配置到日志中,以便后续链路跟踪
|