matrix-org / waterfall

A cascading stream forwarding unit for scalable, distributed voice and video conferencing over Matrix
Apache License 2.0
97 stars 5 forks source link

Run each subscription's packet processing in its own worker #110

Closed daniel-abramov closed 1 year ago

daniel-abramov commented 1 year ago

I've realised that actually that generic helper that I created for the subscriptions to track missing packets (watchdog) is very close in semantics to the concept of a single worker. In fact, the watchdog is just a special case of a worker where the task is an empty {} and the task handler is an empty function. So I decided to generalize it a bit and that almost automatically allowed me to transform watchdog into a subscription worker which handles incoming packets. So it was a fairly elegant transformation that did not touch many parts of the code 🙂

So now, each call to the Subscription.WriteRTP() does not block, but merely sends the packet to the worker that then handles the packets.

I've also made it non-blocking since if the channel blocks in this case, it means that the worker can't keep up with the load and so packet drops are inevitable anyway.

Fixes https://github.com/matrix-org/waterfall/issues/108.