webrtc icon indicating copy to clipboard operation
webrtc copied to clipboard

High latency with small datachannel packets

Open stevenlovegrove opened this issue 1 year ago • 3 comments

Working from head of main, I see very high latency when sending small packets - they are being delivered in bursts with large gaps > 500ms. I'm streaming to chrome via localhost. If I artificially increase the size of my data, I can reduce the latency considerably, so my first thought is that there is some min packet size / buffering issue, though I can't find any parameter to adjust, or piece of code responsible for that.

I've also been trying to reduce latency by disabling retransmits and ordering, but I seem to be hitting https://github.com/webrtc-rs/webrtc/issues/371 which appears unresolved and I can verify that reliability configuration is not properly propagated. Even after I apply https://github.com/zduny/webrtc/commit/8a9138cfd1ddf5c1b32a9579f0033cb4768fa4d5 from @zduny, and ensuring that the appropriate unorder and reliability values are set when getting to association_internal.rs logic, I can see packets are getting appended to the inflight queue and I'm receiving ACKS from the client (as shown when enabling trace logging) and latency isn't lowered. Presumably that is not expected? I can see that my outgoing packets and these ACKS are not interleaved - I can't determine if that is because of the output buffering or some in-flight flush logic?

Any pointers on what I could check in the code regarding these issues (1. buffering, 2. reliability config)?

stevenlovegrove avatar Jan 07 '24 09:01 stevenlovegrove

This is something I have noted as well. I have a temporary workaround which disables some reliability (retransmits) and stats aggregators and congestion control. It works very well with high throughput small packet applications. The fixes are in my repo, but they only work with unreliable datachannels. Do not use them at all if you need any form of reliability. Moreover, this replacing this tokio thing in my application with native threads has resulted in about 10-100x speedup (>240Mbps from a few kbps) on local settings on an old intel i5 (3rd gen). Lowered RAM usage too (consumes only about 7-8 MiB max ram, even with 4 threads).

ris-work avatar Feb 28 '24 17:02 ris-work

@ris-work Very interested in this. Would you mind sharing which fork you mean / which changes you made if they are outdated? Thanks!

martinappberg avatar Aug 15 '24 09:08 martinappberg

@martinappberg: https://github.com/ris-work/webrtc

Same license as webrtc-rs, with my name also included. I have no idea whether the latest merge will build but the one before the latest works well with unreliable streams, never tested reliable ones.

ris-work avatar Aug 25 '24 11:08 ris-work