Open mxinden opened 2 years ago
Relevant discussion happening here: https://github.com/libp2p/rust-libp2p/discussions/3411.
Cross-referencing backpressure tracking issue for Kademlia here https://github.com/libp2p/rust-libp2p/issues/3710.
Cross-referencing a discussion around backpressure: https://github.com/libp2p/rust-libp2p/discussions/4585.
What is backpressure
A slow consumer should slow down (i.e. backpressure) a fast producer.
Why do we need backpressure
See also coding guidelines - Bound everything.
Where do we enforce backpressure
[ ] User ->
Swarm
Swarm::dial
.ConnectionLimit
enforces boundedness at least in thePool
.[ ] User ->
NetworkBehaviour
NetworkBehaviour
viaSwarm::behaviour_mut
libp2p-kad
, manylibp2p-request-response
requests, ...libp2p-kad
have aKademlia::poll_find_closest_ready
that needs to be polled beforeKademlia::find_closest
similar toSink::poll_ready
.[ ]
Swarm
->NetworkBehaviour
[ ]
NetworkBehaviour
->ConnectionHandler
Swarm
does not pollNetworkBehaviour
in case it could not deliver previously returned event from theNetworkBehaviour
to the destinedConnectionHandler
. https://github.com/libp2p/rust-libp2p/blob/f9b4af3d9d5b12b20756e496349b0866baa862da/swarm/src/lib.rs#L1032-L1034NetworkBehaviour
is blocked on single slowConnectionHandler
NetworkBehaviour
already needs to handle the case where the connection closes and thus the event is never delivered to theConnectionHandler
.ConnectionHandler
busy) while the second might be delivered. Not intuitive.NetworkBehaviour
NetworkBehaviour::poll_connection_handler_event
, providing a list ofConnectionId
s withConnectionHandler
s that are ready to receive another event.[ ]
NetworkBehaviour
->Swarm
NetworkBehaviourAction::Dial
[x]
ConnectionHandler
->NetworkBehaviour
ConnectionHandler
is blocked on slowNetworkBehaviour
[ ]
Connection
->ConnectionHandler
ConnectionHandler::inject_fully_negotiated_inbound
ConnectionHandler::inject_fully_negotiated_outbound
ConnectionHandler::inject_event
ConnectionHandler::poll_inject_event_ready
[ ]
ConnectionHandler
->Connection
ConnectionHandlerEvent::OutboundSubstreamRequest
[ ] Stream
Related resources