设置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. 美团点评CAT监控平台研究

    1. 美团点评CAT监控平台研究 1.1. 前言 此文根据我对官方文档阅读并记录整理所得,中间可能会穿插一些自己的思考和遇坑 1.2. 简介 CAT 是基于 Java 开发的实时应用监控平台,为美团点 ...

  2. js学习之数据结构和算法

    js中的数据结构 1.列表 待办事项列表.购物清单.最佳十名榜单等等. 适用: 1)数据结构较为简单, 2)不需要在一个长序列中查找元素,或者对其进行排序 2.栈 一摞盘子 ----- 添加删除只能从 ...

  3. BootStrap简单table

    效果图: 代码如下: <%-- Created by IntelliJ IDEA. User: 冷噫雪 Date: 2019/9/1 Time: 13:06 To change this tem ...

  4. MySQL添加用户、为用户分配权限

    登录MySQL登录本地用户 mysql -u root -p登录外网用户(需要注意服务器可能只允许本地登录,需要修改响应的配置文件) mysql -u zhrt -h 10.64.6.4 -p添加用户 ...

  5. Linux搭建MySQL主从

    实现目标 搭建两台MySQL服务器(一主一从),一台作为主服务器,一台作为从服务器,主服务器进行写操作,从服务器进行读操作. 工作流程概述 主服务器: 开启二进制日志 配置唯一的server-id 获 ...

  6. Jmeter jmeter-server.bat 无法启动

    问题现象: 解决方法: 找到如下文件: 在目录\apache-jmeter-5.0\bin下,打开名为jmeter.properties的文件 找到server.rmi.ssl.disable=fal ...

  7. httprunner学习9-完整的用例结构(yaml&json)

    前言 前面几篇零散的学了一些httprunner的知识点,那么一个完整的 YAML/JSON 用例文件包含哪些关键字呢? 测试用例结构 在 HttpRunner 中,测试用例组织主要基于三个概念: 测 ...

  8. ArcGIS 合并相邻Polygon

    先说效果: 合并前效果:

  9. 使用 application.properties 中配置的属性,举例:@Value("${server.port}")

    使用 application.properties 中配置的属性:@Value 注解. @RestController public class HelloWorldController { @Val ...

  10. C++传递不定参函数

    定义不定参数函数,要用到下面这些宏: va_start(ap, farg): 初始化一个va_list变量ap,farg是第一个形参 va_arg(ap, type): 获取(下)一个type类型的参 ...