Closed coder137 closed 1 year ago
It is fine to open a bidirectional stream and keep it open forever. However, it's probably not the most efficient approach. For example, you seem to be using length-prefixing to delineate messages, which is, to some extent, duplicating functionality that the QUIC protocol already supplies for you. So instead, it would likely make more sense to use one (unidirectional) stream per message. If there is a strict request/response coupling, you might have one bidirectional stream per message, where the "client" starts sending a message and the "server" then responds on the same stream -- the "client" can signal its message is complete by closing its send part of the stream IIRC.
(I've forgetten the details of how connection and stream closes are ordered, but I encourage you to read the source -- we've tried hard to make it (relatively) easy to understand. Someone else may have this knowledge paged in better.)
Length-prefixed messages within a single long-lived stream are still a good solution if you need them to be strictly ordered, which is common.
I would like to do a connection.close and trigger an ApplicationClose to the connected peer. However the reliable stream fails first instead of connection.close being triggered.
I'm not sure what you mean by "the reliable stream fails first". Closing a connection by definition terminates all streams on that connection. If you don't want a stream to be terminated, don't close the connection yet. That might mean waiting for an application-layer response to know when a stream is no longer needed.
Thanks for the comments @djc and @Ralith.
I was able to successfully update my application logic by opening a unidirectional channel on demand instead of the length prefixing option. The code design and implementation were simpler when doing it this way.
To clarify: Are there any performance impacts when opening a unidirectional channel on demand (from the Quinn internals perspective)? Compared to the length prefixing option?
Streams are very cheap. The best way to get a more specific answer than that is profiling.
Streams are very cheap. The best way to get a more specific answer than that is profiling.
Thanks for the confirmation. Will profile it and update my results here eventually.
As per my understanding of the docs opening a unidirectional and bidirectional stream is cheap and instantaneous.
However, For my application, I only need one bidirectional stream between 2 peers (one opens and one accepts)
unidirectional
/bidirectional
stream on demand? I am writing an asynchronous application where the write and read need to happen in a full duplex mode so will be using unidirectional streams to send/recv data.connection.close
and trigger anApplicationClose
to the connected peer. However the reliable stream fails first instead ofconnection.close
being triggered.Diagrams
[My method] Opening bidirectional channel once
Problem: When closing the connection the reliable channel fails first and the other peer does not get the
connection.close
error code.Opening unidirectional channels on demand
Is there a performance impact here?. This is probably my only concern.
This design should solve the flaws of the above design. If you see any other problem please point that out