reinh / statsd

A Ruby Statsd client that isn't a direct port of the Python example code. Because Ruby isn't Python.
MIT License
411 stars 154 forks source link

Fix incorrect time measurement by using monotonic time #70

Closed kyrylo closed 6 years ago

kyrylo commented 6 years ago

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.

kyrylo commented 6 years ago

The errors in the build seem to be unrelated to the changes here (the specs pass locally for me).

raggi commented 6 years ago

Thank you!