设置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。

最新文章

  1. iOS 传值方式
  2. hosts manager——hosts配置管理工具
  3. 4412开发板升级4.2之后改了logo开机后屏幕闪解决办法
  4. hdu 4763 kmp ***
  5. ORACLE随机查询
  6. 关于listview的一些属性
  7. JVM 参数翻译汉化解释
  8. iOS发布条款检查表
  9. java String常见的处理
  10. HNCU1330:算法3-1:八进制数
  11. Python Tornado篇
  12. java导出word
  13. 并发系列(2)之 ThreadLocal 详解
  14. Git综合使用命令行和gui工具小结
  15. 12 week blog
  16. ubuntu12下subversion 1.6升级为1.8版本
  17. 2019年度【计算机视觉&机器学习&人工智能】国际重要会议汇总
  18. 第7天【find命令、if语句、磁盘管理、文件系统管理】
  19. Hadoop教程(五)Hadoop分布式集群部署安装
  20. 洛谷 P4026 [SHOI2008]循环的债务

热门文章

  1. JavaScript设计模式与开发实践随笔(一)
  2. js根据json数组多个字段排序
  3. grpc:超时机制
  4. 怎么解决前端线上Bug
  5. Jmeter CSV参数带汉字处理
  6. Shell 编程 循环语句
  7. Dapper 一对多查询 one to many
  8. List的复制 (浅拷贝与深拷贝)
  9. 13、Python文件处理、os模块、json/pickle序列化模块
  10. 不重装nginx实现动态添加模块