为什么nginx access.log中的request_time比上游_response_time大得多? [英] Why is request_time much larger than upstream_response_time in nginx access.log?
问题描述
我正在尝试提高Web应用程序的性能.对应用程序本身进行性能分析,我发现它的响应时间是可以接受的(100ms-200ms),但是当我使用ApacheBench测试应用程序时,响应时间有时会超过1秒.当我仔细查看日志时,偶尔发现request_time
和upstream_response_time
之间存在很大差异:
I am trying to improve the performance of a web app. Profiling the app itself, I found its response time are quite acceptable (100ms-200ms), but when I use ApacheBench to test the app, the response time sometimes exceeds 1 second. When I looked closely at the logs, I found a big discrepancy between request_time
and upstream_response_time
occasionally:
"GET /wsq/p/12 HTTP/1.0" 200 114081 "-" "ApacheBench/2.3" 0.940 0.286
"GET /wsq/p/31 HTTP/1.0" 200 114081 "-" "ApacheBench/2.3" 0.200 0.086
upstream_response_time
非常接近我在Web应用程序中的配置文件,但是对于第一个请求,request_time
接近一秒钟.
The upstream_response_time
is quite close to my profiling in the web app, but request_time
is close to one second for the first request.
什么会导致这种差异?
我知道request_time
是从接收到的第一个字节记录到发送的最后一个响应字节的记录,它可能会受到网络状况和客户端问题的影响.我想知道应该怎么做才能尽可能地降低平均request_time
?
I understand request_time
is recorded from the first byte received to last response byte sent, it can be affected by network condition and client problem. I am wondering what should I do to reduce the average request_time
as much as possible?
推荐答案
request_time
高可能是由于客户端连接速度较慢,您对此无能为力.因此,高request_time
不一定 代表服务器和/或应用程序的性能.
A high request_time
may be due to a client with a slow connection, for which you can't do much about. Thus, a high request_time
does not necessarily represent the performance of your server and/or application.
在进行概要分析时,您实际上不应该在request_time
上花费太多时间,而应该测量诸如应用程序的响应时间(即upstream_response_time
)之类的东西.
也就是说,您可以执行某些操作,并且可能会影响request_time
.其中一些如下:
That said, there are some things which you are able to do and may affect the request_time
. Some of them are the following:
- Move your server on a high-speed network
- Move your server near the client
- Disable the Nagle's algorithm
- Tune the server's TCP stack (see this article). However these won't necessarily make a big difference since the kernel does a good job of tuning them for you.
这篇关于为什么nginx access.log中的request_time比上游_response_time大得多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!