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. Python笔记二之多线程

    本文首发于公众号:Hunter后端 原文链接:Python笔记二之多线程 这一篇笔记介绍一下在 Python 中使用多线程. 注意:以下的操作都是在 Python 3.8 版本中试验,不同版本可能有不 ...

  2. DDD落地实践-架构师眼中的餐厅 | 京东云技术团队

    本文以餐厅场景为叙事主线,以领域驱动为核心思想,结合架构设计与功能设计方法论.是从领域分析到落地的全过程案例,内容偏重于落地,因此不乏一些探讨,欢迎指正. 文章较长.全程干货.耐心读完.必有收获. 本 ...

  3. pacman下载时经常出现Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds

    问题 我在manjaro系统上使用pacman下载软件的时候,经常出现以下报错: 错误:无法从 mirrors.tuna.tsinghua.edu.cn : Operation too slow. L ...

  4. javacv实现屏幕录制(一)

    javacv实现屏幕录制(一) javacv从入门到入土系列,发现了个好玩的东西,视频处理,于是我想搞个屏幕录屏,我百度了一下,copy那些代码我没有实现过,那些代码也没有说明,只好去官网看文档找资料 ...

  5. PythonAnywhere 部署Flask项目

    一. 注册账号 官网:https://www.pythonanywhere.com/ 二. 将GitHub上的项目发送至PythonAnywhere 三.配置环境及运行 git clone https ...

  6. three.js中帧缓存的使用

    目录 1. 概述 2. 示例 2.1. 代码 2.2. 解析 3. 参考 1. 概述 在网上查阅了一下three.js关于帧缓存的使用,感觉很多都是关于three.js中后处理通道的使用的.后处理通道 ...

  7. windows环境下如何优雅搭建ftp服务?

    目录 0. 前言 1.ftp简介 2.下载Apache FTPServer 3.下载并解压压缩包 4.修改配置文件 4.1 修改users.properties配置文件 4.2 修改ftpd-typi ...

  8. 【华为云技术分享】40%性能提升,华为云推出PostgreSQL 12 商用版

    摘要:日前,华为云数据库正式推出了RDS for PostgreSQL 12版本,并开始商用.本文将从华为云RDS for PostgreSQL 12的4大特性和架构图等多方面来解读华为云Postgr ...

  9. 非洲 AI 不发达,看看这份PPT,受益匪浅

    非洲 AI 不发达,看看这份PPT,受益匪浅 非洲有大量的工程+机器学习人才,他们渴望学习.努力工作和进步. 大家好,我是老章 看到我关注的一位博主在首届非洲 @LangChainAI 聚会上的一个演 ...

  10. 在WPF应用中使用FastReport.WPF报表模块

    FastReport是一个非常不错的报表组件,在Winform应用中常常使用它进行报表的设计.预览展现.打印或者导出文件(PDF.Excel)等,可以设计打印各种各样的报表,本篇随笔继续介绍当前最新的 ...