1、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 。
指的就是从接受用户请求的第一个字节到发送完响应数据的时间,即包括接收请求数据时间、程序响应时间、输出响应数据时间。
 
2、upstream_response_time
官网描述:keeps times of responses obtained from upstream servers; times are kept in seconds with a milliseconds resolution. Several response times are separated by commas and colons like addresses in the $upstream_addr variable
 
是指从Nginx向后端(php-cgi)建立连接开始到接受完数据然后关闭连接为止的时间。
 
从上面的描述可以看出,$request_time肯定大于等于$upstream_response_time,特别是使用POST方式传递参数时,因为Nginx会把request body缓存住,接受完毕后才会把数据一起发给后端。所以如果用户网络较差,或者传递数据较大时,$request_time会比$upstream_response_time大很多。
 
所以如果使用nginx的accesslog查看php程序中哪些接口比较慢的话,记得在log_format中加入$upstream_response_time。
 
根据引贴对官网描述的翻译:
upstream_response_time:从 Nginx 建立连接 到 接收完数据并关闭连接
request_time:从 接受用户请求的第一个字节 到 发送完响应数据

如果把整个过程补充起来的话 应该是:
[1用户请求][2建立 Nginx 连接][3发送响应][4接收响应][5关闭  Nginx 连接]
那么 upstream_response_time 就是 2+3+4+5 
但是 一般这里面可以认为 [5关闭 Nginx 连接] 的耗时接近 0
所以 upstream_response_time 实际上就是 2+3+4 
而 request_time 是 1+2+3+4
二者之间相差的就是 [1用户请求] 的时间

如果用户端网络状况较差 或者传递数据本身较大 
再考虑到 当使用 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的区别

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

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

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

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

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

  4. nginx优化之request_time 和upstream_response_time差别

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

  5. nginx日志request_time 和upstream_response_time区别

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

  6. request_time和upstream_response_time详解

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

  7. nginx 日志相关配置总结

    设置位于nginx.conf:         log_format  main  '$server_name $remote_addr - $remote_user [$time_local] &q ...

  8. 一、基于hadoop的nginx访问日志分析---解析日志篇

    前一阵子,搭建了ELK日志分析平台,用着挺爽的,再也不用给开发拉各种日志,节省了很多时间. 这篇博文是介绍用python代码实现日志分析的,用MRJob实现hadoop上的mapreduce,可以直接 ...

  9. nginx 之 grok 过滤

    简介   前面我们的nginx日志编码使用的json,logstash直接输入预定义好的 JSON 数据,这样就可以省略掉 filter/grok 配置,但是在我们的生产环境中,日志格式往往使用的是普 ...

随机推荐

  1. Git简介及安装

    1 Git简介 Git是一个开源的分布式版本控制系统,可以有效.高速的处理从很小到非常大的项目版本管理. Git是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码 ...

  2. BZOJ1444[Jsoi2009]有趣的游戏——AC自动机+概率DP+矩阵乘法

    题目描述 输入 注意 是0<=P, n , l, m≤ 10. 输出 样例输入 input 1 3 2 2 1 2 1 2 AB BA AA input 2 3 4 2 1 2 1 2 AABA ...

  3. UOJ276 [清华集训2016] 汽水 【二分答案】【点分治】【树状数组】

    题目分析: 这种乱七八糟的题目一看就是点分治,答案有单调性,所以还可以二分答案. 我们每次二分的时候考虑答案会不会大于等于某个值,注意到系数$k$是无意义的,因为我们可以通过转化使得$k=0$. 合并 ...

  4. Android studio 3.1.2报错,no target device found

     Android studio 3.1.2的Android monitor改为Android profiler,直接点这个就可以真机调试,在手机安装相应文件 第二次启动时,再次报错,找不到设备,点一下 ...

  5. 「HNOI2016」最小公倍数

    链接 loj 一道阔爱的分块 题意 边权是二元组(A, B),每次询问u, v, a, b,求u到v是否存在一条简单路径,使得各边权上\(A_{max} = a, B_{max} = b\) 分析 对 ...

  6. zabbix python 微信告警脚本

    测试zabbix的微信告警耗费了大量时间,使用了开源工具(OneOaaS weixin-alert).shell脚本工具(手动执行正常,服务器调用失败),均没有实现相关功能以下是自己优化过的Pytho ...

  7. 自学华为IoT物联网_02 常见物联网通信技术

    点击返回自学华为IoT物流网 自学华为IoT物联网_02 常见物联网通信技术 两类技术: 有线通信技术 无线通信技术 一. 有线通信技术 1.1 物联网有线技术介绍及对比 ETH 主要用于支持以太网标 ...

  8. [CF1107E]Vasya and Binary String【区间DP】

    题目描述 Vasya has a string s of length n consisting only of digits 0 and 1. Also he has an array a of l ...

  9. hexo从零开始

    部署Hexo Hexo官方文档 新建一个文件夹,比如,Blog,然后进入该文件夹下: npm install hexo-cli -g hexo version 安装依赖包 npm install 配置 ...

  10. 「HNOI2016」网络 解题报告

    「HNOI2016」网络 我有一个绝妙的可持久化树套树思路,可惜的是,它的空间是\(n\log^2 n\)的... 注意到对一个询问,我们可以二分答案 然后统计经过这个点大于当前答案的路径条数,如果这 ...