Skip to content
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

perf: improve ipc poll logic #4037

Merged
merged 4 commits into from
Aug 3, 2023
Merged

perf: improve ipc poll logic #4037

merged 4 commits into from
Aug 3, 2023

Conversation

mattsse
Copy link
Collaborator

@mattsse mattsse commented Aug 2, 2023

improve poll logic of ipc connection

this makes it slightly more complicated but now priorities output over input, since output is the real bottleneck if input is high.

ref #4028

@mattsse mattsse requested a review from Rjected as a code owner August 2, 2023 17:39
@mattsse mattsse added the A-rpc Related to the RPC implementation label Aug 2, 2023
@codecov
Copy link

codecov bot commented Aug 2, 2023

Codecov Report

Merging #4037 (b95f9c5) into main (248faa4) will increase coverage by 0.00%.
Report is 1 commits behind head on main.
The diff coverage is 71.73%.

Impacted file tree graph

Files Changed Coverage Δ
crates/rpc/ipc/src/server/connection.rs 73.83% <71.11%> (-0.53%) ⬇️
crates/rpc/ipc/src/server/mod.rs 77.50% <100.00%> (ø)

... and 9 files with indirect coverage changes

Flag Coverage Δ
integration-tests 16.48% <0.00%> (-0.01%) ⬇️
unit-tests 64.19% <71.73%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 25.88% <ø> (ø)
blockchain tree 83.04% <ø> (ø)
pipeline 90.07% <ø> (ø)
storage (db) 74.40% <ø> (ø)
trie 94.70% <ø> (ø)
txpool 47.96% <ø> (ø)
networking 77.46% <ø> (+0.01%) ⬆️
rpc 58.29% <71.73%> (+<0.01%) ⬆️
consensus 63.86% <ø> (ø)
revm 32.71% <ø> (ø)
payload builder 6.58% <ø> (ø)
primitives 87.98% <ø> (+<0.01%) ⬆️

@mattsse mattsse requested a review from rkrasiuk August 3, 2023 11:56
@rkrasiuk rkrasiuk added the C-perf A change motivated by improving speed, memory usage or disk footprint label Aug 3, 2023
Copy link
Member

@rkrasiuk rkrasiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes lgtm, got a couple of questions / requests for clarification

Comment on lines +160 to 169
let mut budget = 5;

// ensure we still have enough budget for another iteration
'outer: loop {
budget -= 1;
if budget == 0 {
// make sure we're woken up again
cx.waker().wake_by_ref();
return Poll::Pending
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not quite clear to me - why do we need to return early? is it because the task is blocking and you want to yield back control to the scheduler?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this ensures this loops doesn't run for too long, since this is polled concurrently with something that also receives responses (from subscriptions)

'inner: loop {
let mut drained = false;
// drain all calls that are ready and put them in the output item queue
if !this.pending_calls.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be bounded?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending_calls futures

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are already effectively bounded by the rate limit params that restrict how many calls can be active

Poll::Ready(res) => {
let item = match res {
Ok(Some(resp)) => resp,
Ok(None) => continue 'inner,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

under which circumstances this can return Ok(None)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for subscriptions responses which are routed differently

Copy link
Member

@rkrasiuk rkrasiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mattsse mattsse added this pull request to the merge queue Aug 3, 2023
Merged via the queue into main with commit 76a6c92 Aug 3, 2023
24 checks passed
@mattsse mattsse deleted the matt/ipc-order-impr branch August 3, 2023 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Related to the RPC implementation C-perf A change motivated by improving speed, memory usage or disk footprint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants