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

feat(net): adaptable request timeouts #789

Merged
merged 13 commits into from
Jan 12, 2023

Conversation

lambdaclass-user
Copy link
Contributor

Closes: #689

This PR adds timeout adapting via RTT estimation for each peer.

@onbjerg onbjerg added C-enhancement New feature or request A-networking Related to networking in general labels Jan 9, 2023
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

amazing, tysm for picking this up

/// Amount of RTTs before timeout
const TIMER_MULTIPLIER: u32 = 4;

// TODO: use a more sophisticated formula
Copy link
Collaborator

Choose a reason for hiding this comment

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

worth having a look how geth does this here

Copy link
Contributor

Choose a reason for hiding this comment

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

Just checked. They use the same formula.

@lambdaclass-user lambdaclass-user marked this pull request as ready for review January 10, 2023 16:27
@lambdaclass-user lambdaclass-user requested review from mattsse and removed request for Rjected January 10, 2023 17:43
@codecov-commenter
Copy link

codecov-commenter commented Jan 10, 2023

Codecov Report

Merging #789 (8de6dab) into main (7c9c2fe) will decrease coverage by 0.02%.
The diff coverage is 80.48%.

@@            Coverage Diff             @@
##             main     #789      +/-   ##
==========================================
- Coverage   73.13%   73.10%   -0.03%     
==========================================
  Files         274      275       +1     
  Lines       28251    28653     +402     
==========================================
+ Hits        20660    20946     +286     
- Misses       7591     7707     +116     
Flag Coverage Δ
unit-tests 73.10% <80.48%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
crates/net/network/src/session/active.rs 84.48% <80.00%> (+0.98%) ⬆️
crates/net/network/src/session/config.rs 83.00% <100.00%> (ø)
...rates/storage/codecs/derive/src/compact/structs.rs 81.81% <0.00%> (-3.64%) ⬇️
crates/storage/codecs/derive/src/compact/mod.rs 94.78% <0.00%> (-0.44%) ⬇️
crates/net/network/src/error.rs 80.76% <0.00%> (-0.40%) ⬇️
crates/net/network/src/manager.rs 49.15% <0.00%> (-0.32%) ⬇️
crates/primitives/src/transaction/mod.rs 89.84% <0.00%> (-0.05%) ⬇️
bin/reth/src/cli.rs 0.00% <0.00%> (ø)
bin/reth/src/lib.rs 12.50% <0.00%> (ø)
bin/reth/src/dirs.rs 0.00% <0.00%> (ø)
... and 30 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

awesome

@@ -159,31 +172,31 @@ impl ActiveSession {
on_request!(req, BlockHeaders, GetBlockHeaders);
}
EthMessage::BlockHeaders(resp) => {
on_response!(self, resp, GetBlockHeaders);
on_response!(resp, GetBlockHeaders);
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh nice

req.request.send_err_response(RequestError::Timeout);
}
}

/// Updates the request timeout with a request's timestamps
fn update_request_timeout(&mut self, sent: Instant, received: Instant) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this makes sense to me,

I'd like to see some sanity tests for this, I think we can split this into to parts:

  • standalone,testable function that does the computation
  • update_request_timeout calls this function and updates the time out

Copy link
Contributor

Choose a reason for hiding this comment

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

Done! Should we #[inline] the helper function?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sg, let's do that!

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

lgtm,
one idea I have is to add an Atomic into the ActiveSessionHandle which holds the timeout, this way we can make use of the value when selecting peers, wdyt?

@MegaRedHand
Copy link
Contributor

MegaRedHand commented Jan 11, 2023

It would be useful. You mean something like this?

// handle.rs
pub(crate) struct ActiveSessionHandle<'a> {
    ...
    pub(crate) request_timeout: &'a AtomicU64,
}

// active.rs
pub(crate) struct ActiveSession {
    ...
    pub(crate) request_timeout: AtomicU64,
}

@mattsse
Copy link
Collaborator

mattsse commented Jan 11, 2023

yeh Arc<AtomicU64> so we can have it in multiple places

@MegaRedHand
Copy link
Contributor

Added!

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

thanks,
can we extract the whole shared atomic from this PR and add this separately? because there some things we need to figure out while doing so

This reverts last two commits
@MegaRedHand
Copy link
Contributor

Yeah, sure. Just pushed the changes. Now i'm going to open an issue.

@mattsse mattsse merged commit 4460dc7 into paradigmxyz:main Jan 12, 2023
@MegaRedHand MegaRedHand deleted the adaptable-request-timeouts branch January 12, 2023 13:23
@mempirate mempirate mentioned this pull request Jan 26, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-networking Related to networking in general C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Monitored/Adaptable request timeouts
5 participants