feat: add recv buffer size option with improved recv buffer capacity recovery#904
feat: add recv buffer size option with improved recv buffer capacity recovery#904NedAnd1 wants to merge 3 commits intohyperium:masterfrom
Conversation
|
Improving the recv buffer performance is a great idea! Though, I wonder why you swap between two? With hyper's http1 path, we keep track of a target minimum read amount (though doesn't have to be dynamic), and before each new message, a call to |
Thanks, that approach does lead to higher memory allocation churn. This observation was initially made by explicitly calling Any additional thoughts or questions? |
Summary
This PR addresses the receiver-side perf issue described in #902
by allowing the frame decoder's read buffer size to be configurable
and by mitigating its capacity degradation with a simple a buffer manager.
Problem
The recv buffer size of the frame decoder is small, and even if its buffer size was increased,
the effective capacity of that buffer would degrade over time and never recover, causing small
read()calls.Solution
Adds a recv_buffer_size option to both
client::Builderandserver::Builder,allowing users to control the initial capacity of the frame decoder's read buffer.
Introduces a
BufferManagerthat proactively recovers buffer capacity for decoders.When the underlying decoder returns Ok(None) (no complete frame available)
and the buffer's capacity has fallen below half the initial capacity,
the manager replaces the primary buffer with a secondary buffer
that has a higher likelihood of being able to reclaim its original buffer space.
This mitigates the BytesMut capacity degradation problem without depending on upstream changes.
Validation
Perf results for a branch including the commits in this PR:
Sender-side PR: #903