Repository navigation
Conversation
…drains fully The sender sent [_sendOffset, _sendEnd) and moved both back to 0 only after a send completed with nothing appended behind it. A connection that always had a command appended while a send was in flight never reached that point, so _sendEnd only grew: after 512 KiB of traffic every new command was refused with "pipelined send buffer full", with one command actually waiting to go. pg had the same loop and fixed it in ce82399. The sender now sends a snapshot of the staged bytes and, once it is out, moves whatever was appended meanwhile to the front, as PgConnection does. No new state. New test, RedisSendBufferTests, drives a RedisConnection through a scripted IRingHost, so the interleaving is exact: each PING is appended before the previous send completes, and every reply is delivered. It pushes 4 x 512 KiB through one connection and checks every command is answered and the bytes sent are exactly the PINGs in order. Confirmed both ways: on f298af0 command 37450 is refused with 524,272 bytes sent; with the fix all 149,798 go through. No redis needed.
Owner
Author
|
Bench, before/after:
No cost: the compaction is a memmove of what was appended during the send. Method: |
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A busy redis connection began refusing every command with
pipelined send buffer fullafter 512 KiB of traffic, even though only one command was waiting to be sent.The sender sent
[_sendOffset, _sendEnd)and moved both back to 0 only when a send completed with nothing appended behind it. On a connection where a command is always appended while a send is in flight, that never happens, so_sendEndonly grew until it reached the fixed 512 KiB buffer. Only a send that happened to drain the buffer fully reset it, so until then every new command was refused (with PINGs, from about the 37,000th on). pg had the same loop and fixed it in ce82399.The sender now sends a snapshot of the staged bytes, and once that is out it moves whatever was appended meanwhile to the front, exactly as
PgConnectiondoes. No new state.Tests
New, in
RedisSendBufferTests:redis: a connection whose sends never fully drain still reuses its send bufferThe test drives a real
RedisConnectionthrough a scriptedIRingHost. The scripted ring completes the connect at once and holds each send and recv until the test completes it, inline, as a reactor would. That makes the interleaving exact: each PING is appended before the previous send completes, and every reply is delivered. The test pushes 4 x 512 KiB through one connection. It checks that every command is answered PONG, and that the bytes sent are exactly the PINGs in order, so the compaction cannot corrupt the stream unnoticed. It needs no redis. The scripted ring accepts timeouts and never fires them, so the test also runs unchanged on top of the open-deadline branch, whoseConnectAsyncarms one.A loopback probe (not committed) did not trigger the bug: 64 workers sending 20,000 PINGs each on one connection to the real redis, 1,280,000 PINGs refused 0 times on main. On loopback the send completes before the next command arrives often enough that the buffer drains. The bug needs a send still in flight at each append, for example on a busy reactor, a slower link, or a full socket buffer.
Suites: Unit 63 (1 pending, as on main), Pg 6, Redis 4, with both sidecars running (nothing skipped).
Hot path: the redis sender loop runs for every command. It now does one snapshot and, when something was appended during the send, one memmove of that tail per send cycle. pg has run this loop since ce82399. Worth a wrk before/after on a quiet box.
Bench: the sender loop now compacts after every snapshot, a memmove of whatever was appended during the send. A redis wrk before/after will follow here once the box is quiet.