https://cloud.tencent.com/developer/article/1767981

首先,澄清一个误区

upstream_response_time必须在upstream配置时才能使用?

答案: 否。

举例:

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向后端建立连接开始到接受完数据然后关闭连接为止的时间。

从上面的描述可以看出,requesttime肯定比upstream_response_time值大;尤其是在客户端采用POST方式提交较大的数据,响应体比较大的时候。在客户端网络条件差的时候,

官方文档: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响应头的时间。

另外,Why is request_time much larger than upstream_response_time in nginx access.log? 的也证实了这点:

如果把整个过程补充起来的话 应该是:   [1用户请求][2建立 Nginx 连接][3发送响应][4接收响应][5关闭 Nginx 连接]

upstream_response_time

  那么 upstream_response_time 就是: 2+3+4+5   但是,一般这里面可以认为 [5关闭 Nginx 连接] 的耗时接近 0   所以 upstream_response_time 实际上就是: 2+3+4

request_time

  request_time 是:1+2+3+4 二者之间相差的就是 [1用户请求] 的时间

问题分析

出现问题原因汇总:

  1. 用户端网络状况较差
  2. 传递数据本身较大
  3. 当使用 POST 方式传参时 Nginx 会先把 request body 缓存起来

  这些耗时都会累积到 [1用户请求] 头上去

  这样就解释了为什么 request_time 有可能会比 upstream_response_time 要大

总结

因为用户端的状况通常千差万别 无法控制,所以并不应该被纳入到测试和调优的范畴里面 更值得关注的应该是 upstream_response_time,所以在实际工作中 如果想要关心哪些请求比较慢的话,记得要在配置文件的 log_format 中加入 $upstream_response_time 。

[转帖]nginx 剖析 request_time和upstream_response_time的误区、区别的更多相关文章

  1. nginx日志request_time 和upstream_response_time区别

    笔者在根据nginx的accesslog中$request_time进行程序优化时,发现有个接口,直接返回数据,平均的$request_time也比较大.原来$request_time包含了用户数据接 ...

  2. nginx request_time 和upstream_response_time

    1.request_time 官网描述:request processing time in seconds with a milliseconds resolution; time elapsed ...

  3. Nginx - request_time和upstream_response_time的区别

    request_time 官网描述:request processing time in seconds with a milliseconds resolution; time elapsed be ...

  4. nginx 日志打印响应时间 request_time 和 upstream_response_time

    设置log_format,添加request_time,$upstream_response_time,位置随意 og_format  main  '"$request_time" ...

  5. nginx源码层面探究request_time、upstream_response_time、upstream_connect_time与upstream_header_time指标具体含义

    背景概述 最近计划着重分析一下线上各api的HTTP响应耗时情况,检查是否有接口平均耗时.99分位耗时等相关指标过大的情况,了解到nginx统计请求耗时有四个指标:request_time.upstr ...

  6. nginx中,$request_uri和$uri的区别

    nginx中,$request_uri和$uri的区别   $request_uri This variable is equal to the *original* request URI as r ...

  7. nginx中root与alias关键字的区别

    前言 近段时间秋招上岸了,于是每天疯狂补各种分布式基础,每天都在痛苦与快乐中度过. 在学习 nginx 的时候,遇到配置上的问题:root 与 alias 的区别,卡了大概三个小时,记录下来警醒自己不 ...

  8. nginx优化之request_time 和upstream_response_time差别

    笔者在根据nginx的accesslog中$request_time进行程序优化时,发现有个接口,直接返回数据,平均的$request_time也比较大.原来$request_time包含了(服务器) ...

  9. request_time和upstream_response_time详解

    下图是request_time. 下图是upstream_response_time. 精准的描述就是:request_time是从接收到客户端的第一个字节开始,到把所有的响应数据都发送完为止.ups ...

  10. 【高性能服务器】Nginx剖析

    引言 Nginx是一个流行的高性能服务器,官方宣称在压力测试下可以支持5万个并发连接,而且占用内存极低.相比于其他昂贵的硬件负载均衡解决方案,Nginx是开源免费的,可以大大降低成本.本文将从一下几个 ...

随机推荐

  1. 单位换算详解:bit、Byte、bps、Bps、pps、Gbps的单位详细说明及换算

    当谈论计算机存储和数据传输时,"bit"(比特)和"Byte"(字节)是两个常见的术语,它们具有不同的含义和用途. 位(bit):"位"来自 ...

  2. windows 和 Linux 下 git status 结果不一致

    解决该问题 运行一下命令即可 git config core.autocrlf true 解释 git config core.autocrlf true 这个命令是在任何支持的操作系统上都可以运行的 ...

  3. 斯坦福 UE4 C++ ActionRoguelike游戏实例教程 15.创建持续效果BUFF

    斯坦福课程 UE4 C++ ActionRoguelike游戏实例教程 0.绪论 概述 本篇文章对应Lecture 18 – Creating Buffs, World Interaction, 71 ...

  4. 云图说 | 华为云GPU共享型AI容器,让你用得起,用得好,用的放心

    摘要:容器以其独特的技术优势,已经成为业界主流的AI计算框架(如Tensorflow.Caffe)的核心引擎,为了进一步解决企业在AI计算性能与成本上面临的问题,华为云推出了AI容器产品. 容器以其独 ...

  5. 云小课|MRS基础原理之CarbonData入门

    阅识风云是华为云信息大咖,擅长将复杂信息多元化呈现,其出品的一张图(云图说).深入浅出的博文(云小课)或短视频(云视厅)总有一款能让您快速上手华为云.更多精彩内容请单击此处. 摘要:CarbonDat ...

  6. 火山引擎 ByteHouse:两个关键技术,揭秘 OLAP 引擎中的数据导入技术

      更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 数据导入是衡量 OLAP 引擎性能及易用性的重要标准之一,高效的数据导入能力能够加速数据实时处理和分析的效率. ...

  7. 脑机接口 | 面向步态&神经电生理研究的非人灵长类模型与系统

    近期,海南大学生物医学工程学院脑机芯片神经工程团队在Frontiers in Neuroscience期刊上发表了题为<面向步态&神经电生理研究的非人灵长类模型与系统>的学术论文. ...

  8. 聚合查询 分组查询 F与Q查询 添加新字段

    目录 聚合查询 aggregate 聚合函数 起别名 分组查询 annotate 注释函数 起别名 分组查询报错 分组查询练习 总结 添加新字段 F与Q查询 F查询 字符串拼接 concat方法 Q查 ...

  9. 电子签章Java后端与前端交互签名位置计算

    电子签章过程中存在着在网页上对签署文件进行预览.指定签署位置.文件签署等操作,由于图片在浏览器上的兼容性和友好性优于PDF文件,所以一般在网页上进行电子签章时,会先将PDF文件转换成图片,展示给用户. ...

  10. 文件描述符&文件句柄

    一.概念 1.1 文件描述符&文件描述符表 文件描述符(file descriptor, fd)是Linux系统中对已打开文件的一个抽象标记,所有I/O系统调用对已打开文件的操作都要用到它.这 ...