设置log_format,添加request_time,$upstream_response_time,位置随意

og_format  main  '"$request_time" "$upstream_response_time" $remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

日志输出效果:

"0.015" "0.015" 10.1.2.3 - - [20/Mar/2017:04:05:49 +0800] "GET /myApp/servlet/TestServlet HTTP/1.1" 200 52 "-" "Mozilla/4.0 (compatible; MSIE 4.0; Windows NT)" "-"

-------------------------------------------------------------------------------

笔者在根据nginx的accesslog中$request_time进行程序优化时,发现有个接口,直接返回数据,平均的$request_time也比较大。原来$request_time包含了用户数据接收时间,而真正程序的响应时间应该用$upstream_response_time。

下面介绍下2者的差别:

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

从上面的描述可以看出,$request_time肯定比$upstream_response_time值大,特别是使用POST方式传递参数时,因为Nginx会把request body缓存住,接受完毕后才会把数据一起发给后端。所以如果用户网络较差,或者传递数据较大时,$request_time会比$upstream_response_time大很多。

所以如果使用nginx的accesslog查看php程序中哪些接口比较慢的话,记得在log_format中加入$upstream_response_time。

nginx 日志打印响应时间 request_time 和 upstream_response_time的更多相关文章

  1. Nginx 日志打印POST数据

    在工作中,开发希望能从Nginx日志中获取POST的数据信息,先记录下来 在日志格式后面加上 $request_body 配置信息 log_format main '$remote_addr - $r ...

  2. nginx日志打印请求响应时间

    log_format  timed_combined  '$remote_addr - $remote_user [$time_local] "$request" ' '$stat ...

  3. nginx 日志打印post请求参数

    在日志格式后面加上 $request_body 配置信息 log_format main '$remote_addr - $remote_user [$time_local] "$reque ...

  4. Centos7 搭建 Flume 采集 Nginx 日志

    版本信息 CentOS: Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x ...

  5. nginx1.14.0日志打印

    nginx日志打印 http属性log_format来设置日志格式 ,参考 https://www.jb51.net/article/52573.htm  <nginx日志配置指令详解> ...

  6. nginx日志request_time 和upstream_response_time区别

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

  7. nginx优化之request_time 和upstream_response_time差别

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

  8. Nginx - request_time和upstream_response_time的区别

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

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

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

随机推荐

  1. SYN泛洪攻击原理及防御

    拒绝服务攻击时,攻击者想非法占用被攻击者的一些资源,比如如:带宽,CPU,内存等等,使得被攻击者无法响应正常用户的请求. 讲泛洪攻击之前,我们先了解一下DoS攻击和DDoS攻击,这两个攻击大体相同,前 ...

  2. 【爬虫】Condition版的生产者和消费者模式

    Condition版的生产者和消费者模式 threading.Condition 在没有数据的时候处于阻塞状态,有数据可以使用notify的函数通知等等待状态的线程运作 threading.Condi ...

  3. layui 自定义字体图标 扩展

    layui的图标取自于阿里巴巴的矢量图标库 Iconfont,同样的,这篇教程也是基于Iconfont进行扩展. 第一步,通过浏览器打开 http://iconfont.cn/ ,访问阿里巴巴矢量图标 ...

  4. Linux操作系统内核参数

    Linux操作系统内核参数 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一./proc目录 /proc目录: 内核把自己内部状态信息及统计信息,以及可配置参数通过proc伪文件系 ...

  5. Ugly Pairs CodeForces - 1156B

    题目链接:https://vjudge.net/problem/CodeForces-1156B 题意:给定一串字符,相邻字符的ASCII码不能是相邻的数字,比如ABC,假设ASCII码为,99 10 ...

  6. 纯数据结构Java实现(7/11)(SegmentTree)

    欢迎访问我的自建博客: CH-YK Blog.

  7. Python中取整的方法floor,ceil,round

    地板函数:math.floor(4.9)=4 天花板函数: math.ceil(4.1)=5 四舍五入: round(4.5)=4 round(4.6)=5

  8. 大数据调度工具oozie详细介绍

    背景 之前项目中的sqoop等离线数据迁移job都是利用shell脚本通过crontab进行定时执行,这样实现的话比较简单,但是随着多个job复杂度的提升,无论是协调工作还是任务监控都变得麻烦,我们选 ...

  9. sublime设置默认字体样式

    因电脑配置的不同,还有个人喜好的不同,有时候想用自己喜欢的字体来写代码,想用自己习惯的字号大小来显示代码.这些又该怎样设置呢? 本节主要介绍下如何设置字体大小和样式 (1)点菜单栏 “Preferen ...

  10. C#程序 -- 以管理员权限运行

    阅读目录 一.判断程序是否以管理员身份运行 C#程序以管理员权限运行 在Vista 和 Windows 7 及更新版本的操作系统,增加了 UAC(用户账户控制) 的安全机制,如果 UAC 被打开,用户 ...