Optimal direct messaging #6144
-
Hi everyone, We use rust-libp2p in our project for both gossiping and direct messaging. We're trying to optimize as much as possible and have noticed an extra round trip between nodes when delivering a direct message. We use QUIC and the request/response behavior for direct messaging. It seems the extra round trip happens because the request/response behavior creates a separate substream for each request. Is this understanding correct? Is this the reason for the extra round trip? If so, is there a way to optimize it away? Perhaps we can reconfigure the behavior or use a better one. Any hints or insights would be very helpful! Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hey @lukaszrzasik. While I haven't got the chance to look at the code yet, I would assume it would be request-response has 2-RTT (somebody who knows the code more might be able to comment better on it) since it is sending the request and awaiting for a response before closing the substream. However, if you dont need the response side of it, maybe oneshot might be better suited? If not, you could create a new behaviour that could reuse the substream when sending a request, which might be more ideal depending on your use-case and what youre trying to optimize for. |
Beta Was this translation helpful? Give feedback.
-
I just double-checked, and yes, with the default config the protocol negotiation for a new substream requires a separate round-trip. We also support You can try overriding the upgrade version in |
Beta Was this translation helpful? Give feedback.
I just double-checked, and yes, with the default config the protocol negotiation for a new substream requires a separate round-trip. We also support
upgrade::Version::V1Lazy
, which allows to send early application data together with the protocol info. I actually thought this was enabled by default, but seems likeV1
is the default.You can try overriding the upgrade version in
swarm::Config::with_substream_upgrade_protocol_override
and see if the extra round-trip still happens.