在nginx中,request_time如何小于upstream_response_time? [英] How can request_time be less than upstream_response_time in nginx?

查看:231
本文介绍了在nginx中,request_time如何小于upstream_response_time?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解nginx的 request_time可以大于上游响应时间,这只是意味着nginx与客户端.

我不明白的是request_time怎么会变小?

我分析了nginx日志,其中nginx在API的前面.大约有260万行,因此我认为这是一个很好的示例(仅分析了API请求,没有静态文件.)

比率的计算方式如下: ratio = request_time / upstream_response_time

比率的平均值为1.04,因此,平均request_timeupstream_response_time大一点点,听起来很合理.

我制作了一个直方图以可视化方式显示.我不了解的是直方图的左侧,其中的值是< 1.0.

解决方案

clock_gettime(CLOCK_MONOTONIC_COARSE)计算的$ upstream_response_time,默认情况下,它可以过去4毫秒,与之相反,由gettimeofday()计算的$ request_time.因此,最终upstream_response_time可能大于response_time.

基于 nginx论坛主题

I understand how nginx's request_time can be larger than upstream_response_time, it simply means that the network connection was slow between nginx and the client.

What I don't understand is how request_time can be less?

I've analysed an nginx log where nginx is in front of an API. There were about 2.6 millions lines, thus I believe it's a good sample (only API requests were analysed, no static files.)

Ratios were calculated like: ratio = request_time / upstream_response_time

The mean of the ratios is 1.04, thus on average request_time is a tiny bit larger than upstream_response_time, which sounds reasonable.

I made a histogram to visualise this. What I don't understand is the left side of the histogram, where values are < 1.0.

解决方案

$upstream_response_time calculated by clock_gettime(CLOCK_MONOTONIC_COARSE), and by default it can be in past for 4 milliseconds, on opposite, $request_time calculated by gettimeofday(). So eventually upstream_response_time might be larger, than response_time.

Based on nginx forum thread

这篇关于在nginx中,request_time如何小于upstream_response_time?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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