Description
In an experiment to replace webrtc-rs with str0m (as many others are looking to do), I ran into some strange delays happening when a javascript client and str0m server have a request/response round trip, where it takes the client ~1.5 seconds to receive the first payload after sending the request. The example code that contains the behavior can be found here: https://github.com/ozwaldorf/str0m-experiment
The request flow looks like this:
sequenceDiagram
Client-->>Server: SDP (HTTP)
Client-->>Server: WebRTC Connection
Client-->>Server: Open data channel
Server->>Client: Send total number of blocks
loop Session
Client->>+Server: Block number request
Client-->Server: Strange 1.5s delay
Server->>Client: Chunk 0
Server->>Client: Chunk 1, 2, ..., 7, 8
end
A client receives the total number of blocks for some content, and can request each block id. Each block is <=256KiB, and is chunked into 32KiB payloads and sent over the webrtc datachannel.
There is a very long time to first byte after sending each request for the next block, around 1.5 seconds, from when the javascript client sends the request to when it receives the first byte. Compared to similar code written with webrtc-rs, there aren't any delays with each ttfb being ~1ms.
The str0m server takes ~1ms to receive the request payload as a datachannel message, and ~220ms to write the 8 chunks to the rtc state and for the last chunk to be sent out over the socket. Should note, ~200ms of that time is a delay between sending the first packet and the second packet, and the rest of the other packets with the payloads only take a few ms between each other to send after that. A possible clue that I was able to find while inspecting network packets (via wireshark), is that there always seems to be a STUN request happening while there are no outgoing payload packets from the server.
I'd appreciate a glance over the example code, and any recommendations if there is any misuse of the library, but I haven't been able to find any glaring issues, thanks!