-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
runtime: async preemption causes short sleep in tickspersecond #63103
Comments
It looks to me that the code calculates ticks per second using the actual time passed and the cpu tick differences https://cs.opensource.google/go/go/+/master:src/runtime/runtime.go;l=36-41 , so a shorter delay should be fine. Do you suggest that we add a comment? Thanks. |
Right, the code is written to not rely on the sleep being exactly 100ms: scheduling delays in the OS could make it longer, async preemption in practice makes it shorter. That's all fine. I'd like the code within that function to match what we see in practice. If it appears to say "sleep for 100ms" but it usually only sleeps for the scheduling quantum (10ms today), then I'd like either for the code to change so it sleeps for the whole 100ms, or for it to explicitly attempt sleeping for one scheduling quantum. I'd like for the various profiles to impose a minimal overhead on applications. For short-lived programs this sort of delay can be a significant source of overhead: given a program that takes only 200ms to run, this adds either 50% (as written, +100ms) or 5% (in practice, +10ms with async preemption). So I'm also interested in ways to avoid delaying the app, maybe via capturing the two clocks unconditionally when the runtime boots up and again at 100ms. Callers of |
Okay, thanks. So the concern is mostly the delay for short-running programs? Sleeping 10ms is probably fine. It is probably long enough for all CPUs to get a good ratio. Calculating it unconditionally at runtime startup also sounds reasonable to me. |
At a high level, I don't like But getting off my high horse, this estimate is probably good enough for our use and I'm not sure we need to overhaul it. I kind of like starting this computation at startup since it is cheap overall. But where would you suggest putting the check for completion? It bugs me a bit to unconditionally put somewhere central like the scheduler. Maybe it could actually go in |
My practical concerns are the delay for short-running programs, and the delay in start-up time for programs that call
The first option is to make the first A second option is for the runtime's boot process to also set a timer, which on expiration (10 or 100ms later) would finish the calculation. Calls to
I get the impression that sysmon isn't very popular. But is sysmon an option for this? |
Change https://go.dev/cl/538898 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, Go 1.21 is the latest release series.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
I expected the code in
runtime.tickspersecond
that callsusleep(100 * 1000)
to result in a delay of 100,000µs (100ms).https://github.com/golang/go/blob/go1.21.1/src/runtime/runtime.go#L35
What did you see instead?
Asynchronous preemption interrupts the call, both on darwin/arm64 and linux/amd64, resulting in a shorter delay (10–20ms).
Maybe the shorter delay is fine (see #63078), but if it's intentional then the code should change to reflect that intent.
The text was updated successfully, but these errors were encountered: