Inconsistent time measurement in Nginx

Zexuan Luo spacewanderlzx at
Tue Sep 28 02:27:55 UTC 2021

Hi, Nginx developers:

Currently, the request_time uses ngx_timeofday to get the time, which
finally will call gettimeofday. Meanwhile, the upstream_x_time series
uses ngx_current_msec to calculate the time, which finally will call

On Linux, the gettimeofday will call clock_gettime(CLOCK_REALTIME,
&ts) while the ngx_monotonic_time will call
clock_gettime(CLOCK_MONOTONIC_COARSE, &ts).

So the request_time uses CLOCK_REALTIME and the upstream_x_time series
uses CLOCK_MONOTONIC_COARSE. As they are different sources, sometimes
we observe that the upstream_response_time is larger than
request_time. This behavior is unexpected and has caused bug in our

A similar report can be also found in

Is this behavior intended? Why not use the same time measurement for
all metrics? Thanks for your reply.

More information about the nginx-devel mailing list