Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connlib): decrease connection setup latency (#4022)
`snownet` is built in a SANS-IO way, which means it doesn't have internal timers or IO. It is up to the upper layer to correctly check `poll_timeout` and call `handle_timeout` as soon as that expires. _When_ we want to be called again (i.e. the result of `poll_timeout`) may change every time `snownet`s internal state changes. This is especially critical during the initial setup of a connection. As we learn about our own candidates and candidates from the other party, we form new pairs. To actually detect whether the pair is a viable network path, we need to send a STUN request. When to send STUN requests is controlled by time. A newly formed pair should send a STUN request as soon as possible to minimize latency. Previously, we did not update the timer upon which we "wake" `snownet` using `handle_timeout`. As such, we waited unnecessarily long before sending STUN requests to newly formed pairs. With this patch, we check `poll_timeout` at end of the `Tunnel`'s `poll` function and immediately call `handle_timeout` in case we need to. Currently, `str0m` throttles updates to `handle_timeout` in 50ms blocks which still creates some delay. With that commented out, I observed improvements of ~0.7s for establishing new connections. Most of the time, the 2nd ping already goes through!
- Loading branch information