[转帖]nginx 日志打印响应时间 request_time 和 upstream_response_time
https://www.cnblogs.com/chooperman/p/14722450.html
设置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 日志打印响应时间 request_time 和 upstream_response_time
设置log_format,添加request_time,$upstream_response_time,位置随意 og_format main '"$request_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反向代理nginx,RealServer日志打印真实ip
title: nginx反向代理nginx,RealServer日志打印真实ip date: 2016-05-11 19:15:37 tags: --- nginx反向代理nginx,RealServ ...
- nginx日志request_time 和upstream_response_time区别
笔者在根据nginx的accesslog中$request_time进行程序优化时,发现有个接口,直接返回数据,平均的$request_time也比较大.原来$request_time包含了用户数据接 ...
- Nginx 改变错误日志打印级别
Nginx 改变错误日志打印级别 user root;worker_processes 2; worker_rlimit_nofile 10240;error_log logs/nginx_err ...
- Nginx日志中的金矿 -- 好文收藏
转:http://www.infoq.com/cn/articles/nignx-log-goldmine Nginx(读作Engine-X)是现在最流行的负载均衡和反向代理服务器之一.如果你是一名中 ...
随机推荐
- vulntarget-a-wp
vulntarget-a 信息收集 存活扫描,目标开放了445还是win7,考虑一手永恒之蓝 arp-scan -l nmap -A -sT -sV 192.168.130.4 永恒之蓝 用nmap的 ...
- Ef Core花里胡哨系列(7) 使用Ef Core也能维护表架构?
Ef Core花里胡哨系列(7) 使用Ef Core也能维护表架构? 我们这里指的并不是查询,而是利用Ef的迁移原理,生成可用的其它表架构操作的Sql. 例如你想在Ef Core里建表,并且可能程序里 ...
- apex的安装过程及问题解决(ModuleNotFoundError:No module named 'packaging')
最近在复现代码时遇到了如下问题,在此记录一下问题的解决过程: 步骤一 git clone https://github.com/NVIDIA/apex.git 步骤二 cd apex 步骤三 pip ...
- 在winform blazor hybrid中绘图
前几天跟大家介绍了在winform中使用blazor hybrid,而且还说配上blazor的ui可以让我们的winform程序设计的更加好看,接下来我想以一个在winform blazor hybr ...
- Typora+Docsify快速入门
Typora是什么? Typora中文版是一款好用极简的跨平台Markdown编辑器,软件使用这款软件能够帮助用户轻松将文本转换到HTML,软件从底层向上设计,软件支持markdown的标准语法, ...
- 如何快速部署本地训练的 Bert-VITS2 语音模型到 Hugging Face
Hugging Face是一个机器学习(ML)和数据科学平台和社区,帮助用户构建.部署和训练机器学习模型.它提供基础设施,用于在实时应用中演示.运行和部署人工智能(AI).用户还可以浏览其他用户上传的 ...
- 率先支持Kuasar!iSulad Sandbox API 简化调用链,沙箱管理能力增强
本文分享自华为云社区<率先支持Kuasar!iSulad Sandbox API 简化调用链,可靠性倍增>,作者:云容器大未来 . 沙箱隔离技术是一种将进程有效隔离到独立环境中运行的技术. ...
- 号外!5G+X联创营华为云官网上线,5G 创业春天来了!
摘要:为助力互联网行业客户与伙伴实现降本增效.抓住新趋势,华为云发起"5G+X"联创营计划. 会议室里,产品经理和程序员们唇枪舌战,陷入激烈得讨(zheng)论(chao). 产品 ...
- 优化了MYSQL大量写入问题,老板奖励了1000块给我
摘要:大家提到Mysql的性能优化都是注重于优化sql以及索引来提升查询性能,大多数产品或者网站面临的更多的高并发数据读取问题.然而在大量写入数据场景该如何优化呢? 今天这里主要给大家介绍,在有大量写 ...
- Intellij IDEA 显示 access.log 日志
先配置 SpringBoot 记录 access.log 日志,先让accesslog 显示出来