quinn-rs / quinn

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

Architecture question: Is possible/recommended to open millions of streams? #1401

Closed jvdwrf closed 2 years ago

jvdwrf commented 2 years ago

Hi,

I would like to use Quinn within another library, but I am wondering about my overall architecture. I would like to have many processes on one machine communicate with many on another machine.

I saw that the default max_bidi_streams and max_uni_streams are set to 100. Is it recommended to have connections multiplexed over the QUIC or should I build a custom abstraction on top of QUIC? I'm talking about (many) millions of multiplexed streams here.

Thanks, Jasper

jvdwrf commented 2 years ago

To make the question a bit more clear, I see a few methods to do this:

  1. Every process on one machine has a bidi_stream to a process on another machine. This can exponentially increase the amount of streams, since every unique combination of processes could have a unique stream.
  2. Every process on one machine who wants to send messages to another machine gets a uni_stream which it can use to send messages to another process. Replies will be sent back to a single process, which then forwards the reply to the original sender.
  3. There is a single bidi_stream which all processes use. This stream is then multiplexed to all processes, both on sending-side and receiving side using channels.
Ralith commented 2 years ago

Large numbers of streams is a supported case. Each active stream has a modest amount of memory overhead, particularly if the peer is sending data faster than you're reading it, so you should think carefully about resource exhaustion risks before raising the limits that high, and perhaps shrink the per-stream flow control windows, but it's not necessarily a bad idea; large numbers of channels, for example, have fundamentally the same issue.

jvdwrf commented 2 years ago

Okay thats perfect. I'll try to use the quic streams directly then and see how that works out.