-
-
Notifications
You must be signed in to change notification settings - Fork 348
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
Which clock should we use on Windows? #33
Comments
@tkerwin reported in chat that they have a program that misbehaves on windows if trio uses How risky is it? It looks like libuv uses I guess I'd still like to see the output from these commands on some Windows system:
(On my linux laptop, they both give ~0.05 µs/loop) |
On Windows 10, with an i5-3570:
|
Meh, 50 ns is like an attribute lookup or two, I think spending that once or twice per pass through the run loop is fine if it's giving better user-visible behavior. @tkerwin Any interest in putting together a PR? |
Change to high-resolution clock per #33
Resolved in #33 |
And in #682 :) |
For reference, on macOS 10.14 with a mid-2014 Macbook Pro:
It also takes about 80nsec per loop. |
When the progress bar is updated frequently (every few milliseconds), the eta can change so quickly that it's impossible to read. This means we're calling monotonic/time often, but those calls take less than 100 nsec per loop on Linux, Windows and macOS [0], which is equivalent to one attribute lookup or two. [0]: python-trio/trio#33
@pquentin That makes sense. There's some confusing indirection to trace through, but if I'm reading it right, when CPython is built for anything besides Windows, |
When the progress bar is updated frequently (every few milliseconds), the eta can change so quickly that it's impossible to read. This commit updates the average while sma_window is being filled, then after every second. This means we're calling monotonic/time often, but those calls take less than 100 nsec per loop on Linux, Windows and macOS [0], which is equivalent to one attribute lookup or two. [0]: python-trio/trio#33
…lity. As per python-trio/trio#33 PiperOrigin-RevId: 291783317
15 ms resolution is totally enough for I/O timeouts! |
to adds some info for the thread: Python 3.11 is going to fix detailed content as always |
Right now we use
time.monotonic
everywhere. This is a bit problematic on Windows, wheretime.monotonic
isGetTickCount64
, which has ~15 ms resolution. The other option isQueryPerformanceCounter
, which has much higher resolution, is also monotonic, and is exposed astime.perf_counter
(checked withtime.get_clock_info
).The reason for this appears to be that
QueryPerformanceCounter
has had a troubled past: https://www.python.org/dev/peps/pep-0418/#windows-queryperformancecounterBut all these issues are like "Virtualbox had a bug that was fixed 6 years ago" or "Windows XP is flaky" which is probably true but irrelevant since we don't support it – it's not clear that any of them apply anymore.
Advantages of using a higher-precision clock:
Right now if there's just one task running and it does a sleep for t seconds, the actual timeout passed to the underlying system call will be
(t + current_time()) - current_time()
, which can be pretty imprecise depending on whether the clock ticks over between the two calls. OTOH I don't know what the actual resolution of our sleeping syscall is (currentlyGetQueuedCompletionStatusEx
), or whether anyone cares about millisecond accurate sleeps.I've had two bugs already with tests that assumed that time always, like, passes. These were trivial (like replacing a
<
with a<=
), but it's always annoying to have the tests pass locally then fail on appveyor.If we implement a fancier scheduling system (Design: alternative scheduling models #32) then we'll definitely need better than 15 ms precision to measure tasks running. (Though there's no reason that the clock we use for that has to match the clock we use for deadlines.)
The text was updated successfully, but these errors were encountered: