quinn-rs / quinn

Async-friendly QUIC implementation in Rust
Apache License 2.0
3.76k stars 380 forks source link

Proto-layer endpoint/connection communication #1726

Open Ralith opened 9 months ago

Ralith commented 9 months ago

Gives us freedom to adopt more specialized communication strategies (e.g. atomics or fine-grained locks) between endpoints and connections. These will need to be implemented at the proto layer, because optimal strategies will be sensitive to the specific data proto-private being communicated, e.g. NeedIdentifiers as an atomic counter.

Simplified take on https://github.com/quinn-rs/quinn/pull/1650, pushing cheeky data structures to future work.

Ralith commented 9 months ago

The main effect of this PR is to replace the requirement that quinn-proto users pass endpoint and connection events around themselves with the requirement that users trigger wakeups when events have occurred, with quinn-proto managing the actual message-passing internally. This is not necessarily more modular, but could be useful because it allows future work to replace naive message-passing with more specialized structures as in #1650. A more specialized communications structure could be lighter: an AtomicUsize counter is much lighter than message-passing for requesting new connection IDs and has constant memory overhead, for example. We still need to dispatch wakeups, but unlike messages, those are idempotent and hence don't need to be buffered, which might simplify downstream code.

It's not obvious that the benefit here is significant as it stands. quinn wasn't simplified, because it still needs the same channels for other purposes. Perhaps those can be addressed in future work; e.g. quinn::ConnectionEvent could probably be reduced to a set of shared flags.

My real goal is to work towards fine-grained interior mutability in quinn-proto, particularly Endpoint, to eventually support parallel endpoint drivers. I don't think this PR moves us in that direction.

This is also a step towards resolving https://github.com/quinn-rs/quinn/issues/1131, but the real substance of the hazard described there is in handling datagrams, which is unchanged, and could be addressed without this PR.

This effort was ultimately exploratory, and I'm open to shelving it until it's more strongly motivated.