nginx 日志打印响应时间 request_time 和 upstream_response_time
设置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的更多相关文章
- Nginx 日志打印POST数据
在工作中,开发希望能从Nginx日志中获取POST的数据信息,先记录下来 在日志格式后面加上 $request_body 配置信息 log_format main '$remote_addr - $r ...
- nginx日志打印请求响应时间
log_format timed_combined '$remote_addr - $remote_user [$time_local] "$request" ' '$stat ...
- nginx 日志打印post请求参数
在日志格式后面加上 $request_body 配置信息 log_format main '$remote_addr - $remote_user [$time_local] "$reque ...
- 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 ...
- nginx1.14.0日志打印
nginx日志打印 http属性log_format来设置日志格式 ,参考 https://www.jb51.net/article/52573.htm <nginx日志配置指令详解> ...
- nginx日志request_time 和upstream_response_time区别
笔者在根据nginx的accesslog中$request_time进行程序优化时,发现有个接口,直接返回数据,平均的$request_time也比较大.原来$request_time包含了用户数据接 ...
- nginx优化之request_time 和upstream_response_time差别
笔者在根据nginx的accesslog中$request_time进行程序优化时,发现有个接口,直接返回数据,平均的$request_time也比较大.原来$request_time包含了(服务器) ...
- Nginx - request_time和upstream_response_time的区别
request_time 官网描述:request processing time in seconds with a milliseconds resolution; time elapsed be ...
- nginx源码层面探究request_time、upstream_response_time、upstream_connect_time与upstream_header_time指标具体含义
背景概述 最近计划着重分析一下线上各api的HTTP响应耗时情况,检查是否有接口平均耗时.99分位耗时等相关指标过大的情况,了解到nginx统计请求耗时有四个指标:request_time.upstr ...
随机推荐
- linux route路由
网关(Gateway)又称网间连接器.协议转换器.网关在网络层以上实现网络互连 就好像一个房间可以有多扇门一样,一台主机可以有多个网关.默认网关的意思是一台主机如果找不到可用的网关,就把数据包发给默认 ...
- ThreadLocal概述、以及存在的坑
ThreadLocal: 线程的一个本地化对象.当多线程中的对象使用ThreadLocal维护变量是,ThreadLocal为每个使用该变量的线程分配一个独立的变量副本. threadlocal通常定 ...
- HBase的部署与其它相关组件(Hive和Phoenix)的集成
HBase的部署与其它相关组件(Hive和Phoenix)的集成 一.HBase部署 1.1.Zookeeper正常部署 首先保证Zookeeper集群的正常部署,并启动之: /opt/module/ ...
- Prometheus学习笔记(1)Prometheus架构简介
Prometheus简介和架构 Prometheus 是由 SoundCloud 开源监控告警解决方案.架构图如下: 如上图,Prometheus主要由以下部分组成: Prometheus Serve ...
- 分析一个UBOOT的方法
1. 编译完成后可以看到在主目录下生成了uboot.bin文件,为了方便分析,使用如下命令将其反汇编:arm-linux-objdump -D -m arm u-boot > u-boot.as ...
- Linux系统的安装-2019-11-11
1.虚拟机上的每个步骤 2,加载光盘镜像 3.内核相关的信息: Linux Redhat-7-43.cn 3.10.0-957.27.2.el7.x86_64 主版本号:3 次版本号:10[奇数为 ...
- Introduction to Linux Threads
Introduction to Linux Threads A thread of execution is often regarded as the smallest unit of proces ...
- ES6 手册
不用就忘, 把阮大大的地址列在这儿: http://es6.ruanyifeng.com/#README
- JavaScript数组常用操作方法
ES5操作数组的方法 1.concat() concat() 方法用于连接两个或多个数组.该方法不会改变现有的数组,仅会返回被连接数组的一个副本. var arr1 = [1,2,3]; var ar ...
- CMDS目的端数据库碎片整理记录
CMDS目的端数据库碎片整理记录 看看数据库里面需要做整理的表有哪些,条件可以根据需求稍微改动一下 SQL> select * from ( 2 select a.owner, 3 a.tabl ...