Repository navigation
Conversation
Prevent slow-reading peers from retaining excessive outbound data by reserving framed payload bytes before Netty queues write tasks. Close a peer above 200 MiB and evict the largest pending writer when the shared budget reaches 500 MiB. Global pressure triggers asynchronous eviction, not a hard admission cap. Close connections when writes remain incomplete for ten seconds and release reservations on write completion or failure. Avoid per-message budget logging while holding the shared accounting lock.
| @Slf4j(topic = "net") | ||
| final class WriteBufferHandler extends WriteTimeoutHandler { | ||
|
|
||
| private static final Budget GLOBAL_BUDGET = new Budget(200L * 1024 * 1024, 500L * 1024 * 1024); |
There was a problem hiding this comment.
Nice work! Could you share how the 200 MiB per-connection limit in GLOBAL_BUDGET was chosen? I’d like to make sure it leaves enough headroom for normal block sync, so honest peers don’t get disconnected while syncing.
There was a problem hiding this comment.
The 200 MiB limit applies to outstanding outbound writes on a single connection. The budget is released when a write completes or fails, so it does not limit the cumulative amount of data transferred during sync.
Based on our production observations, blocks are typically around 100 KB. With at most 100 blocks requested per batch, that amounts to roughly 10 MB of block data, leaving substantial headroom below the 200 MiB threshold. Completed writes also continuously release the budget as data is sent, so normal syncing is generally not expected to hit this limit.
However, 100 KB is a typical size, not an upper bound. Consecutive large blocks or network congestion can still cause pending data to accumulate, and these edge cases need further validation.
|
Thanks for working on this. Two things I noticed while reading the change:
|
|
One more thought on how the slow-peer case is detected. Netty's writability could make the limits both tighter and gentler on honest peers, if it is used on the producer side rather than as an eviction signal:
This is a bigger change than the current p2p-only approach, so it may fit better as a follow-up, but it seemed worth raising here since it addresses both the memory bound and the honest-peer eviction. |
What does this PR do?
Add pending-write accounting and timeout handling to improve TCP connection resource management.
The shared threshold triggers asynchronous eviction rather than enforcing a hard global admission limit.
Why are these changes required?
This PR has been tested by:
Follow up
Extra details