-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sleep seems too fast #2716
Comments
It's simple, we use JRuby seems to currently have the same limitation: https://github.com/jruby/jruby/blob/f6ca739fbd4fc3fa101adb34ee319be6a78b232d/core/src/main/java/org/jruby/RubyKernel.java#L734 There is also In general, I guess sleeps below 1ms are not portable across platforms and probably rarely accurate. |
I have a fix.
So there is quite a large overhead for these tiny sub-millisecond sleeps. With
With
|
I was wondering if the extra clock_gettime()s around the actual sleep are the cause of the overhead but it seems not.
And it's not the overhead of the call either, because if I replace the sleep with
So I guess it's a potential issue with In any case, sub-millisecond sleep like 0.0001 is problematic. Even on CRuby it's a 50% overhead. |
Thanks for investigating this. One could consider "sleep being too fast" to be an optimisation to make the program faster :) This could be a problem for an event loop - sleeping not long enough can cause it to burn cycles calling sleep again. I'd advise that we should never sleep for less than what was requested. |
…2716) PullRequest: truffleruby/3479
Thanks for fixing this so quickly. |
Report by @ioquatix
https://github.com/socketry/timers/blob/710aea96aa90b96a45df8e5fc0bab9dcbe447f6d/fixtures/timer_quantum.rb
https://github.com/socketry/timers/runs/8149588088?check_suite_focus=true#step:4:8
I added some prints:
Output:
The text was updated successfully, but these errors were encountered: