Skip to content

Avoid redundant Redis cluster command and reply copies - #3702

Open
songgaoye wants to merge 1 commit into
apache:masterfrom
songgaoye:perf/redis-cluster-mget-move
Open

songgaoye wants to merge 1 commit into
apache:masterfrom
songgaoye:perf/redis-cluster-mget-move

Conversation

@songgaoye

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: resolve

Problem Summary:

RedisClusterChannel makes avoidable copies while parsing commands and
aggregating MGET replies:

  • Parsed commands are copied into the command list after construction.
  • Each sub-reply is shared into an intermediate vector and then shared again
    into the final Redis reply, causing redundant IOBuf block-reference
    operations.

What is changed and the side effects?

Changed:

  • Move completed ParsedCommand objects into the parsed command list.
  • Move each MGET sub-reply into the intermediate reply vector.
  • Move intermediate replies into the final aggregated reply.

Side effects:

  • Performance effects:

    Avoids copying command argument vectors and eliminates two IOBuf
    block-reference copy/release cycles per aggregated MGET element.

  • Breaking backward compatibility:

    None.


Check List:

@songgaoye songgaoye changed the title perf: avoid redundant Redis cluster command and reply copies Avoid redundant Redis cluster command and reply copies Nov 3, 2026
@songgaoye
songgaoye force-pushed the perf/redis-cluster-mget-move branch from 4651cd2 to d664990 Compare November 3, 2026 02:20
@wwbmmm
wwbmmm requested a lite review from Copilot November 3, 2026 03:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change has an active critical correctness issue that can truncate sufficiently large GET replies, along with an additional efficiency issue in the same construction path.

2 open issues
What changed in this PR

This PR reduces redundant copying in RedisClusterChannel while parsing commands and aggregating Redis MGET replies.

Changes:

  • Moves completed ParsedCommand objects into the command list.
  • Moves MGET sub-replies into the intermediate reply collection.
  • Moves intermediate replies into the final encoded response.
File Description Review findings
src/​brpc/​redis_cluster.cpp Applies move-based command parsing and MGET reply aggregation. Critical (1 vote): The push_back conversion from IOBuf::Movable can truncate sufficiently large GET replies and leave the big-view allocation unmanaged; use a transfer operation that preserves big views. Nit (2 votes): Use emplace_back to avoid materializing and copying a temporary IOBuf.

Review effort: Lite

return false;
}
values.push_back(sub_result.encoded_reply);
values.push_back(sub_result.encoded_reply.movable());
return false;
}
values.push_back(sub_result.encoded_reply);
values.push_back(sub_result.encoded_reply.movable());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants