Xpra-org / xpra

Persistent remote applications for X11; screen sharing for X11, MacOS and MSWindows.
https://xpra.org/
GNU General Public License v2.0
1.93k stars 165 forks source link

quic congestion control #4202

Open totaam opened 5 months ago

totaam commented 5 months ago

Improving upon #3376, see also #3854.

My understanding of aioquic packet loss is that QuicConnection Instantiates a QuicPacketRecovery, which is a Packet loss and congestion controller. There is no easy way to override this class. Loss detection happens in _detect_loss Which calls _on_packets_lost In turn, this calls delivery_handlers (see below) and the congestion controller

The congestion_control_algorithm string comes from the QuicConfiguration and defaults to reno. The congestion control algorithm is instantiated by create_congestion_control New implementations can be registered via register_congestion_control

The abstract base class QuicCongestionControl Has useful methods: on_packets_lost, on_rtt_measurement, etc

The on_packets_lost congestion control methods only affect the congestion_window and other congestion attributes:

At a lower level: the QuicPacketBuilder.start_frame records an optional handler for each buffer head it creates. This is used for calling methods such as _on_ping_delivery


When we send data: https://github.com/Xpra-org/xpra/blob/e3b595a231a01d41ec139bbb79fe6eb994c26e53/xpra/net/quic/connection.py#L124 This ends up just calling self._quic.send_stream_data(stream_id, encode_frame(FrameType.DATA, data), end_stream) which just creates a QuicStream if needed, and then calls write on the QuicStreamSender


TODO, question and ideas:

totaam commented 3 months ago

We can probably subclass RenoCongestionControl or CubicCongestionControl or both, and override on_packets_expired + on_packets_lost to take some actions beyond the default congestion control algorithms.

If we register it:

register_congestion_control("xpra", XpraCongestionControl)

Then it can easily be configured (perhaps just via an env var for now): https://github.com/aiortc/aioquic/blob/a6d91fbcb5d7660adb1597bb711f6f963c598e03/src/aioquic/quic/configuration.py#L29