-
Notifications
You must be signed in to change notification settings - Fork 999
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
[RFC][libp2p-swarm] Let network I/O run ahead of NetworkBehaviour polling. #1585
Conversation
I agree that this is an improvement, however I worry that many |
I'm quite conflicted about this change. After this PR, if a node task happens to be slow, rather than freezing the network, all the other node tasks will continue to deliver events, which will be delivered to the In other words, this PR removes the back-pressure on libp2p tasks that comes into play when the The If we indeed do this, I believe that the change to make |
This would also eliminate the back-pressure on the TCP connections themselves. |
Yes, absolutely, I share the concerns about the buffers. What I wanted to highlight and primarily seek agreement on in this PR is the fact that the problem of buffering and back-pressure needs to be propagated to the behaviour in a connection-oriented way, because handling it in the Swarm as is done right now makes all progress be subject to the slowest connection. |
Would it be possible to introduce an additional API to |
The above notion of |
I don't think that would work, because it would essentially require access to the underlying |
While changing |
@mxinden The design of libp2p already permits such thing, not on a connection level but on a substream level. Once a |
@mxinden Sure, you can implement backpressure via an embedded flow-control protocol, but I'm not sure that is the most effective thing to do: Such an embedded flow-control is a form of implementing backpressure by sending friendly messages of the form "Please don't send me any more data until I say so". Notably these flow-control events are sent through (bounded) channels which themselves already offer a means for backpressure by slowing down the speed at which new work (in the form of events) is accepted, leaving at each point the producer of these work items with the consequences of not being able to submit them as fast as it wants to (which usually means further propagation of backpressure). @tomaka The ability to directly hand over control of negotiated substreams from the connection/protocols handler to the |
Closing in favour of #1586. |
The design of
libp2p-swarm
is currently such that it tries to progress the underlyingNetwork
and the associatedNetworkBehaviour
in tandem, that is, to poll both with roughly equal frequency. In particular, if theNetwork
has more events (isReady
) but a connection handler is not ready to receive an event emitted by the behaviour, the swarm waits until notified of the handler being ready to make progress again. This PR is a proposal for letting theNetwork
make progress arbitrarily far ahead of theNetworkBehaviour
, only subject to back-pressure from the consumer of the swarm events. This is done bycontinue
ing the swarm loop instead of returningPoll::Pending
in all the cases where a connection handler is currently busy. To be more precise (from the code comments):Point (3.) implies that instead of letting the connection event buffers in
libp2p-core
be filled just because a single connection (handler) is slow, the buffering, if there is any, is left to the behaviour (with no direct means for back-pressure, for now). That seems like the better choice because it allows the behaviour and network I/O to make progress (albeit not beingpoll()
ed again until the slow connection handler consumes the pending event).This obviously has a few consequences on how one writes robust
NetworkBehaviour
s and as mentioned in points (1.) and (3.) is still not free of problems, but may be a step in the right direction.