Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can request_time be less than upstream_response_time in 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.

histogram

like image 926
hyperknot Avatar asked Dec 30 '18 15:12

hyperknot


1 Answers

$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

like image 158
vanadium23 Avatar answered Nov 20 '22 21:11

vanadium23