Created
May 7, 2020 12:24
-
-
Save g-andrade/508c779a931dde14c22c6e96319caa24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(drift_test). | |
-export([run/1]). | |
run(Timeout) -> | |
MonoStartTs = erlang:monotonic_time(millisecond), | |
OsStartTs = os:system_time(millisecond), | |
receive | |
after | |
Timeout -> | |
MonoFinishTs = erlang:monotonic_time(millisecond), | |
OsFinishTs = os:system_time(millisecond), | |
#{ milliseconds_elapsed => | |
#{ according_to_monotonic_clock => MonoFinishTs - MonoStartTs, | |
according_to_os_clock => OsFinishTs - OsStartTs | |
} | |
} | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested on OTP
21.3.8.15
and GNU/Linux with a4.15.0
kernel.Root cause of the issue appears to be the use of
CLOCK_MONOTONIC
instead ofCLOCK_BOOTTIME
when callingclock_gettime
- I think.(This doesn't necessarily apply to other platforms.)
Configuring ERTS with
--enable-prefer-elapsed-monotonic-time-during-suspend
solved the issue; this makes sense, as the default value of the setting appears to beno
.