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(kad): Limit number of active outbound streams #3287

Merged

Conversation

nazar-pc
Copy link
Contributor

@nazar-pc nazar-pc commented Dec 28, 2022

Description

Limit number of active outbound streams to not exceed configured number of streams.

Resolves #3236.

Notes

The approach taken here restricts number of active outbound substreams and all extra are put into the queue.
Since some outbounds streams might not actually exist in the handler temporarily if request for outbound stream was issued, a separate variable is used to keep track of those as well.

As the result we maintain a bounded number of outbound streams that matches the limit for inbound streams on the other side.

Links to any relevant issues

#3235
#3236

Open Questions

Not entirely sure how to test higher-level behavior here as I'm new to the codebase, though changes are somewhat straightforward.
Also there is no support for cancelling of outbound streams, though it didn't seem to be possible before either, so reasonable timeouts before retries are your friends.

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

@nazar-pc nazar-pc changed the title Limit number of active outbound streams feat(kad): Limit number of active outbound streams Dec 28, 2022
Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

👍

protocols/kad/src/handler.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this @nazar-pc!

protocols/kad/src/handler.rs Outdated Show resolved Hide resolved
protocols/kad/src/handler.rs Outdated Show resolved Hide resolved
protocols/kad/src/handler.rs Outdated Show resolved Hide resolved
@mxinden
Copy link
Member

mxinden commented Jan 2, 2023

Note that in my opinion we should get rid of the manually written state machines long-term in libp2p-kad handler.rs. See #3130. Though that should be a separate pull request.

Copy link
Contributor Author

@nazar-pc nazar-pc left a comment

Choose a reason for hiding this comment

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

Simplified implementation a bit based on review comments

@nazar-pc nazar-pc requested a review from mxinden January 4, 2023 17:22
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

LGTM

A few minor suggestions but not blocking!

protocols/kad/src/handler.rs Outdated Show resolved Hide resolved
protocols/kad/src/handler.rs Show resolved Hide resolved
protocols/kad/src/handler.rs Outdated Show resolved Hide resolved
protocols/kad/src/handler.rs Outdated Show resolved Hide resolved
protocols/kad/src/handler.rs Outdated Show resolved Hide resolved
protocols/kad/CHANGELOG.md Outdated Show resolved Hide resolved
thomaseizinger
thomaseizinger previously approved these changes Jan 16, 2023
protocols/kad/src/handler.rs Outdated Show resolved Hide resolved
@thomaseizinger
Copy link
Contributor

Thanks, this is good to merge from my end. We will have to wait until the interoperability tests are fixed. See libp2p/test-plans#99 (comment).

mxinden
mxinden previously approved these changes Jan 16, 2023
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Wonderful. This looks good to me. Thanks for the work. Thanks for the follow-ups.

Next step would be to propagate backpressure to the NetworkBehaviour implementation. Let me know in case you are interested in implementing that. I would expect this patch alone to suffice for the issues (#3236) you are facing.

@mergify mergify bot dismissed stale reviews from thomaseizinger and mxinden January 17, 2023 05:21

Approvals have been dismissed because the PR was updated after the send-it label was applied.

@mxinden
Copy link
Member

mxinden commented Jan 17, 2023

Once #3331 is merged we can proceed here.

@nazar-pc
Copy link
Contributor Author

On our small testnet results are very promising so far

thomaseizinger
thomaseizinger previously approved these changes Jan 24, 2023
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Let's go!

@mxinden
Copy link
Member

mxinden commented Jan 24, 2023

@Mergifyio refresh

@mergify
Copy link
Contributor

mergify bot commented Jan 24, 2023

refresh

✅ Pull request refreshed

@mxinden
Copy link
Member

mxinden commented Jan 24, 2023

Seems like Mergify is stuck on the initial failure on the interoperability tests. They are green on the second run. Will merge master in the hope for mergify to forget the initial failure.

@mergify mergify bot dismissed thomaseizinger’s stale review January 24, 2023 16:05

Approvals have been dismissed because the PR was updated after the send-it label was applied.

@mergify mergify bot merged commit 520523b into libp2p:master Jan 24, 2023
@nazar-pc nazar-pc deleted the limit-number-of-active-outbound-streams branch January 24, 2023 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kademlia: Records republication exceeds inbound stream limit
4 participants