Backpressure in Kademlia
Open
Nobody has claimed this yet.
tracking-issue
- Dominant language
- Rust
- Stars
- 5.6k
- Forks
- 1.3k
- Avg merge
- 8h 47m
- Merged PRs (30d)
- 19
Description
See https://github.com/libp2p/rust-libp2p/issues/3078 for tracking issue on backpressure in rust-libp2p in general.
Terminology
-
Query and request
Backpressure
- User ->
KademliaNetworkBehaviour- No backpressure on any of the query methods, e.g.
Kademlia::get_closest_peerstoday.
https://github.com/libp2p/rust-libp2p/blob/75f967f4da2bb023d8ad2594e63dd887672151cc/protocols/kad/src/behaviour.rs#L656-L660 Kademliahas 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::Sinkstyle signature withpoll_get_closest_peers_readyand aget_closest_peers. Kademlianeeds some criteria to decide when to returnPoll::Pendinginpoll_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.
- No backpressure on any of the query methods, e.g.
Kademlia->ConnectionHandler- Mechansim through
ToSwarm::GenerateEventdoes not enforce backpressure (yet). - Create an
futures::channel::mpsc::channelbetween 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
OutboundStreamRequestin-flight, read from the channel from theNetworkBehaviouronly onConnectionEvent::FullyNegotiatedOutbound.
- Mechansim through
- local
ConnectionHandlerto remoteConnectionHandler- Backpressure through muxers stream creation backpressure mechanism (exists in QUIC, tracked in https://github.com/libp2p/rust-yamux/issues/150 for yamux)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with protocols/kad/src/behaviour.rs and the protocols/kad/src/query entry points, then review how Kademlia communicates with ConnectionHandler instances through ToSwarm::GenerateEvent. Compare the proposed futures channel and stream approaches, including muxer backpressure, and identify the design decision needed before implementation. Done requires an agreed mechanism that applies backpressure across the user, Kademlia, and connection-handler boundaries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- distributed-systems, networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100