For a Rust Yamux stream, the flow-control window and the receive buffer are related but not interchangeable: the window limits how much the peer may send, while the buffer stores bytes that have arrived but have not yet been read by your application. If you want a slow reader to slow the sender, choose read-driven window updates and keep reads progressing while writes are pending.
How Yamux flow control relates to a receive buffer
Yamux multiplexes independent streams over one reliable, ordered connection. In the Rust yamux crate, a Connection wraps the underlying I/O resource and exposes streams implementing futures::io::AsyncRead and AsyncWrite. Yamux is its own protocol; it is not HTTP/2. The current crate documentation observed here is for version 0.14.1, while APIs and defaults in other Rust implementations may differ.
As an Amazon Associate I earn from qualifying purchases.
Think of the two receive-side concepts as separate controls:
- Flow-control window: the receiver’s sending credit. It determines how far the remote sender may advance before it needs more credit.
- Receive buffer: local storage for data already received but not yet consumed by application code.
When a receiver processes data, it can advance the allowed offset and grant the sender more credit. In a read-driven policy, application reads drive that progress: if the application stops reading, the remote sender eventually runs out of credit. That is the mechanism by which a slow consumer can apply backpressure upstream. The libp2p Yamux documentation describes flow control through backpressure as a key feature.
#1 Best Overall
Choose when the window is updated
The libp2p wrapper’s behavior makes the update policy consequential. The versioned libp2p-yamux 0.47.0 source documentation distinguishes updates on receipt from updates on read.
| Policy | Effect on a slow application reader | What to account for |
|---|---|---|
| Update on read | Reading advances credit, so a slow application reader can exert backpressure on the remote sender. | Keep polling reads while writes are pending; otherwise, bidirectional streams can deadlock when both peers exhaust their windows. |
| Update on receive | Credit is replenished as data arrives, so slow application reads do not themselves provide stream-level backpressure. | Received-but-unread data can accumulate. The implementation documentation warns that the receive buffer can overflow unless its maximum suits the throughput and slow-reader periods the workload must tolerate. |
Updating on read is the more direct choice when application consumption should regulate the sender. Updating on receipt may suit a workload that needs credit replenished independently of reads, but it makes an appropriate receive-buffer bound especially important. Neither setting determines every layer’s memory use: decoding, queued streams, and application work queues can also retain data.
Rank #2
Prevent a bidirectional read/write deadlock
Read-driven backpressure has a coordination requirement. If both peers write until their receive windows fill, then wait for those writes to finish before reading, neither peer may make the read progress needed to restore credit. The libp2p-yamux 0.47.0 source explicitly warns about this deadlock scenario.
Structure the application so a blocked write does not stop read polling on the same bidirectional stream. For example, use concurrently progressing read and write futures or tasks, with appropriate coordination for shared state and cancellation. The key is not a particular task layout: reads must remain able to drain inbound data while writes are waiting for peer capacity.
Rank #3
Set limits across the whole receive path
There is no single buffer size established as suitable for every Rust Yamux application. First identify the exact crate and version, then inspect its current configuration API and buffering behavior rather than transferring a setting or default from another wrapper.
The minip2p-yamux 0.4.7 documentation lists 256 KiB as Yamux’s specification-defined initial stream receive window. That is a protocol initial-window figure for that documentation, not a universal Rust implementation default, a recommended application buffer size, or a throughput benchmark.
When tuning, consider aggregate memory as well as per-stream behavior. Many active streams can multiply individually modest allowances. Where the implementation or application exposes controls, bound unread bytes, frame decoding, inbound stream queues, active stream counts, and downstream work queues. Choose limits based on the workload’s tolerated bursts and slow-reader periods; the cited documentation does not establish universal numeric limits for those layers.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Decide whether you need a separate multiplexer
Before configuring Yamux, check the transport. In libp2p, QUIC, WebTransport, and WebRTC are listed as transports with native streams, which may remove the need for an additional muxing layer. The libp2p multiplexing overview describes transport negotiation and native-stream options.
If a separate muxer is required, compare the choices by their receive behavior and compatibility needs:
| Option | Receive-side behavior | When it fits |
|---|---|---|
| Yamux, updates on read | Application reads can slow the remote sender through flow control. | A separate muxer is needed and slow-consumer pressure should reach the sender, with reads kept active during writes. |
| Yamux, updates on receive | Credit replenishes as data arrives, independently of application reads. | The desired throughput behavior justifies separately bounding unread receive data. |
| mplex | It provides no flow control, and libp2p documentation says it does not limit the number of peer-opened streams. | Primarily a legacy interoperability requirement, not a flow-controlled workload. |
| Transport-native streams | The transport supplies streams, potentially avoiding an extra muxer. | A selected transport such as QUIC, WebTransport, or WebRTC already provides the needed stream model. |
The libp2p mplex documentation states that mplex does not provide flow control. Your choice should account for native transport streams, whether slow reads should throttle the sender, aggregate memory across concurrent streams, existing-peer compatibility, and whether reads continue while writes are blocked.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minute




