Skip to content

feat: yamux receive window auto-tuning #1270

@asabya

Description

@asabya

Summary

The yamux stream muxer in py-libp2p currently uses a fixed 256KB receive window, which limits throughput on high-bandwidth links. Other libp2p implementations (notably go-yamux) implement receive window auto-tuning that dynamically grows the window up to 16MB based on RTT measurements.

Proposed Change

Implement yamux receive window auto-tuning that:

  • Starts at the default 256KB window size
  • Doubles the target receive window each RTT epoch when the buffer is being consumed quickly
  • Caps at 16MB max receive window (matching go-yamux)
  • Sends WINDOW_UPDATE frames to the peer as the window grows

This is the same algorithm used in go-yamux.

Implementation

A working implementation is available in #1269 and is currently being tested in the unified-testing perf suite (see libp2p/unified-testing#62).

Key changes:

  • Added MAX_WINDOW_SIZE = 16 * 1024 * 1024 constant
  • Added target_recv_window tracking per stream
  • Added _auto_tune_and_send_window_update() method that grows the window based on consumption rate
  • Called on every read() and _read_stream_data() to keep the window responsive

Impact

Perf test results show significant throughput improvement with auto-tuning enabled, particularly for upload/download benchmarks over tcp+yamux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions