Stop pollProgress from spinning after the input stream closes - #165
Merged
slinkydeveloper merged 1 commit intoAug 21, 2026
Merged
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Flo4604
marked this pull request as ready for review
August 17, 2026 22:02
slinkydeveloper
approved these changes
Aug 18, 2026
slinkydeveloper
left a comment
Contributor
There was a problem hiding this comment.
This sounds right, thanks for fixing it! Once I merge i'll do a patch release
readInputLoop closes readChan on EOF, and a closed channel is always ready, so the select took that case on every iteration. That burned one core per in-flight restate.Run closure. Request-response mode only, as bidirectional keeps the request body open. Set readChan to nil so the case blocks instead.
Flo4604
force-pushed
the
fix/pollprogress-spin-on-closed-input
branch
from
August 20, 2026 15:13
94c398b to
1f440d0
Compare
Contributor
|
Thank you! Release 1.0.4 |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR
When using Bidirectional(false) and Restate.Run its possible to burn CPU due to
pollProgresswhen usingBidirectional(false)When doing 12 concurrent invocations that each sleep 4 seconds we spend 40.84s of CPU across 28.4M
DoProgresscalls, and the sdk callsNotifyInputClosed28,476,268 times instead of once per run.The fix is setting
readChanto nil once input closes, which stops theselectL110 to burn the cpu and taking the same workload to 0.04s at identical wall clock.readInputLoopclosesreadChanon EOF, and a closed channel is always ready to receive, so theselecttook that case every time instead of waiting for the run closure.7ff0fa6(#86) introduced this when EOF went from a sentinel value to closing the channel,with the Bidirectional (default) mode it keeps the request body open, so
readChannever closes and the bug never happens. Thats probably why it never got foundBlocking here is safe as with input closed the shared core v7.0.3 (
async_results.rs:128) returnsWaitingExternalProgressonly while a run in the awaited set is still executing, and that run always completes onrunClosureCompletions.Otherwise it suspends, so a wakeup always remains.
A different approach would be to listen to the shared cores
waiting_input: falsefield butinternal/proto/internal.proto:79declareswaiting_external_progressasEmptyso we cant read that in the go sdk yet.It could be passed trough instead and let the
selectwait onreadChanonly whenwaiting_inputis true.Happy to do that version if that is preferred
Reproduction:
Start a Restate server, then run this service:
On
mainthe service holds about one core per call for the full 4 seconds:With the fix it never goes above
0.02.Also checked:
-race: timer,Runthen timer thenRun, awakeable, concurrent mixed load. All pass.selectentered with input closed and no run in flight. Counted across the whole suite, it never happens.Links