Statsd#time uses the Time class to measure the difference between
elapsed time. This is incorrect because Time.now uses realtime,
which is meant to be used for system clock.
clock_gettime from time.h supports monotonic time. Let me quote
the man page of clock_gettime man to demonstrate the difference
between them:
CLOCK_REALTIME
the system's real time (i.e. wall time) clock, expressed as the
amount of time since the Epoch.
CLOCK_MONOTONIC
clock that increments monotonically, tracking the time since an
arbitrary point, and will continue to increment while the system is
asleep.
Since we measure elapsed time, we should be using monotonic time,
since it more accurate and meant to be used for that reason.
Statsd#time
uses theTime
class to measure the difference between elapsed time. This is incorrect becauseTime.now
uses realtime, which is meant to be used for system clock.clock_gettime
fromtime.h
supports monotonic time. Let me quote the man page ofclock_gettime
man to demonstrate the difference between them:Since we measure elapsed time, we should be using monotonic time, since it more accurate and meant to be used for that reason.