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. |
Tested on OTP 21.3.8.15
and GNU/Linux with a 4.15.0
kernel.
Root cause of the issue appears to be the use of CLOCK_MONOTONIC
instead of CLOCK_BOOTTIME
when calling clock_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 be no
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result of executing it with a 30 seconds timeout while suspending the computer for roughly 20 seconds within the timeout window.
OS clock is in the right here - according to my phone timer, execution was blocked for roughly ~50 seconds (even though a 30 seconds timeout was specified and the computer awoke just upon the 30 seconds window coming to a close.)