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的更多相关文章

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

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

  2. Nginx 日志打印POST数据

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

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

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

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

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

  5. 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 ...

  6. nginx1.14.0日志打印

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

  7. nginx反向代理nginx,RealServer日志打印真实ip

    title: nginx反向代理nginx,RealServer日志打印真实ip date: 2016-05-11 19:15:37 tags: --- nginx反向代理nginx,RealServ ...

  8. nginx日志request_time 和upstream_response_time区别

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

  9. Nginx 改变错误日志打印级别

    Nginx 改变错误日志打印级别 user  root;worker_processes  2; worker_rlimit_nofile 10240;error_log logs/nginx_err ...

  10. Nginx日志中的金矿 -- 好文收藏

    转:http://www.infoq.com/cn/articles/nignx-log-goldmine Nginx(读作Engine-X)是现在最流行的负载均衡和反向代理服务器之一.如果你是一名中 ...

随机推荐

  1. 技巧:在Excel或Word中将回车替换掉

    一.在Excel中替换 将回车替换为逗号或其他字符,如下面的屏幕截图所示. 1. 在 查找和替换 对话框中 查找内容 字段,请按 Ctrl + J 键,然后在 更换 字段中,键入所需的字符,在这种情况 ...

  2. Pikachu漏洞靶场 XSS(跨站脚本攻击)

    XSS 关于xss的我也是一知半解,所以只放出payload来. 反射型xss(get) 修改maxlength属性之后提交如下内容: <script>alert(/xss/);</ ...

  3. 网站优化之favicon.ico

    本文于2015年底完成,发布在个人博客网站上. 考虑个人博客因某种原因无法修复,于是在博客园安家,之前发布的文章逐步搬迁过来. 背景 某一天在办公室分析产品首页加载速度时,无意中从Chrome浏览器的 ...

  4. Windows环境下为Android编译OpenCV4.3

    Windows环境下为Android编译OpenCV4.3 踩了三四天的坑,今天终于顺利跑通了,原来是toolchain的问题,外网的教程大多都是用opencv source里的toolchain,会 ...

  5. 16、Flutter Wrap组件 实现流布局

    Wrap可以实现流布局,单行的Wrap跟Row表现几乎一致,单列的Wrap则跟Column表现几乎一致.但 Row与Column都是单行单列的,Wrap则突破了这个限制,mainAxis上空间不足时, ...

  6. 3、Container容器组件

    Container容器组件 代码 import 'package:flutter/material.dart'; void main() {   runApp(MaterialApp(     hom ...

  7. Llama2-Chinese项目:7-外延能力LangChain集成

      本文介绍了Llama2模型集成LangChain框架的具体实现,这样可更方便地基于Llama2开发文档检索.问答机器人和智能体应用等. 1.调用Llama2类   针对LangChain[1]框架 ...

  8. echarts label formatter params backgroundColor rich 标签设置背景图并传参

    小技巧 如果想给label设置背景图,需要使用到rich属性,按照官网示例就可以实现,折线.柱图都一样. 但是大多数情况formatter都是用来通过params里面参数设置自定义的逻辑,如何将两者结 ...

  9. C++篇:第十三章_异常_知识点大全

    C++篇为本人学C++时所做笔记(特别是疑难杂点),全是硬货,虽然看着枯燥但会让你收益颇丰,可用作学习C++的一大利器 十三.异常 ① 函数指针与该指针所指的函数必须具有一致的noexcept异常说明 ...

  10. 云图说|图解制品仓库CodeArts Artifact

    摘要:制品仓库用于存放由源码编译生成的.可运行的二进制文件,重要作用是实现制品文件的可信存储,支撑软件开发活动. 本文分享自华为云社区<[云图说]第277期 图解制品仓库CodeArts Art ...