响应时间,你真的算对了吗?

发表于:2017-11-23 13:48

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:铲子哥 搜狗测试    来源:51Testing软件测试网采编

  今天对nginx的accesslog中响应时间进行性能测试时,发现有个接口,直接返回数据,平均的响应时间也比较大。网上查了下,原来log中用的响应时间是$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向后端(php-cgi)建立连接开始到接受完数据然后关闭连接为止的时间。
  从上面的描述可以看出,$request_time肯定比$upstream_response_time值大,特别是使用POST方式传递参数时,因为Nginx会把request body缓存住,接受完毕后才会把数据一起发给后端。所以如果用户网络较差,或者传递数据较大时,$request_time会比$upstream_response_time大很多。
  注意事项
  所以如果使用nginx的accesslog查看php程序中哪些接口比较慢的话,记得在log_format中加入$upstream_response_time。
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号