为什么nginx access.log中的request_time比上游_response_time大得多? [英] Why is request_time much larger than upstream_response_time in nginx access.log?

查看:508
本文介绍了为什么nginx access.log中的request_time比上游_response_time大得多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试提高Web应用程序的性能.对应用程序本身进行性能分析,我发现它的响应时间是可以接受的(100ms-200ms),但是当我使用ApacheBench测试应用程序时,响应时间有时会超过1秒.当我仔细查看日志时,偶尔发现request_timeupstream_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:

  • 在高速网络上移动服务器
  • 将服务器移到客户端附近
  • 禁用 Nagle的算法
  • 调整服务器的TCP堆栈(请参见本文).但是,由于内核在为您进行调优方面做得很好,因此这些并不一定会有很大的不同.
  • 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆