V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
happywowwow
V2EX  ›  NGINX

关于 request_time 和 upstream_response_time

  •  
  •   happywowwow · 2016-05-18 22:38:06 +08:00 · 3779 次点击
    这是一个创建于 2902 天前的主题,其中的信息可能已经有所发展或是发生改变。

    贴一部分 nginx 的 access.log 的数据, 分别是

    method, request_time, upstream_response_time, request_time - upstream_response_time

    "GET 0.143 1.131 0.988
    "GET 0.053 0.053 0
    "POST 0.029 0.029 0
    "GET 0.037 3.034 2.997
    "GET 0.138 0.690 0.552
    "POST 0.072 0.072 0
    "GET 0.063 3.833 3.77
    "GET 0.056 1.055 0.999
    "POST 0.029 3.471 3.442
    "GET 0.347 0.378 0.031
    "GET 0.074 3.899 3.825
    "GET 0.077 0.077 0
    "GET 0.018 0.018 0
    "GET 0.030 0.030 0
    "GET 0.034 0.034 0
    "GET 0.063 0.063 0
    "POST 0.031 0.035 0.004
    "POST 0.031 0.031 0
    "POST 0.030 0.030 0
    "GET 0.077 3.552 3.475
    "GET 0.137 0.140 0.003
    "POST 0.030 0.033 0.003
    "GET 0.285 1.557 1.272
    "GET 0.056 0.056 0
    "GET 0.076 3.960 3.884
    "GET 0.076 3.453 3.377
    "POST 0.124 0.186 0.062
    "HEAD - 0.000 0
    "GET 0.007 1.006 0.999
    "POST 0.031 0.925 0.894
    "POST 0.032 0.032 0
    "GET 0.048 0.675 0.627
    "POST 0.030 0.030 0
    

    想了解一下在 cpu, 内存都没满的情况下, 为什么 request_time 和 upstream_response_time 在部分请求中相差这么大.

    以我现在的了解, request_time 是外网请求进出 nginx 的时间

    而 upstream_response_time 是 nginx 将请求交给后端服务器处理到返回的时间

    第 1 条附言  ·  2016-05-18 23:50:09 +08:00
    顺序 应该是

    method, upstream_response_time, request_time, request_time - upstream_response_time
    10 条回复    2016-05-18 23:49:50 +08:00
    eric6356
        1
    eric6356  
       2016-05-18 22:42:29 +08:00
    因为 client 和 server 之间的网络情况各不相同吧?
    ryd994
        2
    ryd994  
       2016-05-18 23:32:00 +08:00
    是不是两个时间反了? request_time>upstream_response_time 才对
    因为 nginx 有 buffer ,在返回数据量不大的情况下,数据全部进 buffer ,关闭上游连接,然后慢慢发给 client
    happywowwow
        3
    happywowwow  
    OP
       2016-05-18 23:34:37 +08:00
    @ryd994 没有反啊 第四列数据都是大于等于 0 的
    happywowwow
        4
    happywowwow  
    OP
       2016-05-18 23:34:47 +08:00
    @eric6356 诶? 什么意思
    eric6356
        5
    eric6356  
       2016-05-18 23:41:04 +08:00
    @happywowwow request_time 是 nginx 接到 request 的时间,然后 nginx 会等 client 把全部的数据发过来存 buffer ,再交给 upstream 。 client 和 server 之间的网络情况各不相同,这会导致这个时间差各不相同。
    happywowwow
        6
    happywowwow  
    OP
       2016-05-18 23:43:29 +08:00
    @eric6356 部分请求需要 秒 级别的返回 这算是正常么
    eric6356
        7
    eric6356  
       2016-05-18 23:43:47 +08:00
    @happywowwow 具体讲的可能有点不对,但大致是这个意思
    ryd994
        8
    ryd994  
       2016-05-18 23:46:08 +08:00
    @happywowwow 第一行 0.143 1.131 你说哪个大?
    eric6356
        9
    eric6356  
       2016-05-18 23:48:38 +08:00
    @happywowwow 我认为很正常,国内的网络,某些时候跨运营商跳来跳去能访问到已经很不容易了。
    happywowwow
        10
    happywowwow  
    OP
       2016-05-18 23:49:50 +08:00
    @ryd994 啊.. 才发现 写反了..

    method, upstream_response_time, request_time, request_time - upstream_response_time
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1150 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 18:23 · PVG 02:23 · LAX 11:23 · JFK 14:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.