fix: remove unnecessary wakes #109
Draft
+209
−412
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.
Background
When running unichain-builder in staging I saw excessive context switching (~60k/sec). Looking into the pipeline API I noticed that the
PipelineExecutormade a call tocx.waker().wake_by_ref()in the manualFuture::pollimplementation, which seemed the likely culprit. That call tells the tokio executor to immediately poll the same future again, but since the cursor is not ready to advance yet, we end up going to that wake line very quickly because we don't do anything. This causes a hot loop in the tokio executor leading to heavy context switching.However, simply removing the
cx.waker().wake_by_ref()calls was not sufficient. What then ended up happening was that the tokio executor got starved and other tasks were severely delayed, which was caught by unichain-builder integration tests. So in addition to removing the wake calls I added in a yield point.Changes
PipelineExecutorrefactorCursorenum and associated state management, this removed a lot of linesThe execution flow is now:
Cooperative yielding: Added a
tokio::task::yield_now().awaitcall after each step transition to prevent executor starvation. I didn't investigate what the best placement for this would be, but this spot works for the unichain-builder tests I was checking.