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

Backpressure in Kademlia #3710

Open
mxinden opened this issue Mar 30, 2023 · 1 comment
Open

Backpressure in Kademlia #3710

mxinden opened this issue Mar 30, 2023 · 1 comment
Labels
tracking-issue Issues which are the entry point to bigger projects.

Comments

@mxinden
Copy link
Member

mxinden commented Mar 30, 2023

See #3078 for tracking issue on backpressure in rust-libp2p in general.

Terminology

  • Query and request

    // Note on the difference between 'request' and 'query': A request is a
    // single request-response style exchange with a single remote peer. A query
    // is made of multiple requests across multiple remote peers.

Backpressure

  • User -> Kademlia NetworkBehaviour
    • No backpressure on any of the query methods, e.g. Kademlia::get_closest_peers today.
      /// Initiates an iterative query for the closest peers to the given key.
      ///
      /// The result of the query is delivered in a
      /// [`KademliaEvent::OutboundQueryCompleted{QueryResult::GetClosestPeers}`].
      pub fn get_closest_peers<K>(&mut self, key: K) -> QueryId
    • Kademlia has no way to signal to the user that it is not yet ready to accept a new query.
    • Could change the method signature to a futures::Sink style signature with poll_get_closest_peers_ready and a get_closest_peers.
    • Kademlia needs some criteria to decide when to return Poll::Pending in poll_get_closest_peers_ready.
    • Ideally no magic maximum of concurrent queries, but instead dynamic limit, e.g. based on capacity to ConnectionHandlers, or only accept new queries in case existing ones can not make progress.
  • Kademlia -> ConnectionHandler
    • Mechansim through ToSwarm::GenerateEvent does not enforce backpressure (yet).
    • Create an futures::channel::mpsc::channel between behaviour and handler at handler creation time.
    • Give query engines access to the channels to each handler, thus being able to make informed decisions where to send which request to.
    • On the handler side, use a new stream per request, have at most one OutboundStreamRequest in-flight, read from the channel from the NetworkBehaviour only on ConnectionEvent::FullyNegotiatedOutbound.
  • local ConnectionHandler to remote ConnectionHandler
@mxinden mxinden added difficulty:hard help wanted decision-pending Marks issues where a decision is pending before we can move forward. labels Mar 30, 2023
@thomaseizinger thomaseizinger changed the title [Tracking Issue] Backpressure in Kademlia Backpressure in Kademlia Sep 19, 2023
@thomaseizinger thomaseizinger added the tracking-issue Issues which are the entry point to bigger projects. label Sep 19, 2023
@thomaseizinger
Copy link
Contributor

Removing decision-pending because I think we agree that there should be backpressure. It is still open on how to solve that.

@thomaseizinger thomaseizinger removed decision-pending Marks issues where a decision is pending before we can move forward. difficulty:hard help wanted labels Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracking-issue Issues which are the entry point to bigger projects.
Projects
None yet
Development

No branches or pull requests

2 participants