Skip to content

rpc: add DRPC stream multiplexing behind an env gate#170248

Open
shubhamdhama wants to merge 4 commits into
cockroachdb:masterfrom
shubhamdhama:add-stream-multiplexing
Open

rpc: add DRPC stream multiplexing behind an env gate#170248
shubhamdhama wants to merge 4 commits into
cockroachdb:masterfrom
shubhamdhama:add-stream-multiplexing

Conversation

@shubhamdhama
Copy link
Copy Markdown
Contributor

Bumps DRPC to pick up stream multiplexing from cockroachdb/drpc#58,
where a single transport connection can carry multiple concurrent
streams.

The multiplexing dial path is guarded by
COCKROACH_EXPERIMENTAL_DRPC_MUX_ENABLED, defaulted to false. With the
gate off, DialDRPC keeps using drpcpool, which checks out a connection
per active stream and dials a new one when none is idle. The upgraded
multiplexing-capable library is therefore exercised on every connection,
but the multiplexing capability itself stays unused: every stream still
ends up on its own underlying connection, matching the prior behavior.

This keeps the initial scope small. The dial-mux path is in place so
it can be turned on for validation, with a follow-up to flip the
default once we are confident.

Both paths now share the same dial-option setup, so the mux path also
picks up the client metrics and the request-recording gate that the
pool path was already attaching.

Release note: None
Epic: none

Adds a small helper that bumps the DRPC replace directive in go.mod to
a specific commit. It takes a GitHub commit URL (cockroachdb or
shubhamdhama fork), resolves the pseudo-version with `go list`,
rewrites the replace line, runs `go mod tidy`, and regenerates the
Bazel files via `./dev generate bazel --mirror`.

Bumping DRPC was a multi-step ritual; the script removes the chance
of forgetting one of the steps.

Release note: None
Epic: none
@shubhamdhama shubhamdhama requested a review from a team May 13, 2026 08:41
@shubhamdhama shubhamdhama requested review from a team as code owners May 13, 2026 08:41
@shubhamdhama shubhamdhama added the do-not-merge bors won't merge a PR with this label. label May 13, 2026
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented May 13, 2026

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@shubhamdhama
Copy link
Copy Markdown
Contributor Author

shubhamdhama commented May 13, 2026

🚨 Remove do-not-merge label checklist

  1. remove do-not-merge commits
  2. remove personal DRPC fork SHA with cockroach fork SHA

Bumps DRPC to pick up stream multiplexing from cockroachdb/drpc#58,
where a single transport connection can carry multiple concurrent
streams.

The multiplexing dial path is guarded by
COCKROACH_EXPERIMENTAL_DRPC_MUX_ENABLED, defaulted to false. With the
gate off, DialDRPC keeps using drpcpool, which checks out a connection
per active stream and dials a new one when none is idle. The upgraded
multiplexing-capable library is therefore exercised on every connection,
but the multiplexing capability itself stays unused: every stream still
ends up on its own underlying connection, matching the prior behavior.

This keeps the initial scope small. The dial-mux path is in place so
it can be turned on for validation, with a follow-up to flip the
default once we are confident.

Both paths now share the same dial-option setup, so the mux path also
picks up the client metrics and the request-recording gate that the
pool path was already attaching.

Release note: None
Epic: none
@shubhamdhama shubhamdhama force-pushed the add-stream-multiplexing branch from b4179ad to cc1edf7 Compare May 13, 2026 09:18
@cockroach-teamcity cockroach-teamcity added the X-perf-gain Microbenchmarks CI: Added if a performance gain is detected label May 13, 2026
Copy link
Copy Markdown
Contributor

@Nukitt Nukitt left a comment

Choose a reason for hiding this comment

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

LGTM! approving since you're already tracking the do-not-merge items.

Comment thread pkg/rpc/drpc.go
log.Dev.Infof(ctx, "dialing DRPC mux connection to %s", target)
return dialDRPCMux(ctx, target, drpcDialOptions)
}
log.Dev.Infof(ctx, "dialing DRPC non-mux connection to %s", target)
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.

Won't this and the one above this make the logs a lot noisier since we'll be logging every dial. Maybe lets have some verbosity flag if thats possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh yes. I'll remove these. They were better for debugging.

@shubhamdhama shubhamdhama removed the X-perf-gain Microbenchmarks CI: Added if a performance gain is detected label May 14, 2026
@shubhamdhama
Copy link
Copy Markdown
Contributor Author

shubhamdhama commented May 15, 2026

Multiplexing off

> benchdiff --bazel --old af827678d69715b0cb134f4bc71404034632cdfc --count 20 --benchtime 1000x ./pkg/sql/tests --run Sysbench/SQL/3node/olt
p_read_write --memprofile --cpuprofile
old:  af82767 do-not-merge: enable DRPC
new:  2a00e41 do-not-merge: always on DRPC for unit tests
args: benchdiff "--bazel" "--old" "af827678d69715b0cb134f4bc71404034632cdfc" "--count" "20" "--benchtime" "1000x" "./pkg/sql/tests" "--run" "Sysbench/SQL/3node/oltp_read_write" "--memprofile" "--cpuprofile"

building benchmark binaries for af82767: do-not-merge: enable DRPC [bazel=true] 1/1 \
building benchmark binaries for 2a00e41: do-not-merge: always on DRPC for unit tests [bazel=true] 1/1 \
name                                           old time/op    new time/op    delta
Sysbench/SQL/3node/oltp_read_write-24            14.0ms ± 4%    15.0ms ± 3%  +6.60%  (p=0.000 n=20+18)
ParallelSysbench/SQL/3node/oltp_read_write-24     994µs ± 7%    1064µs ± 6%  +7.02%  (p=0.000 n=20+19)

name                                           old errs/op    new errs/op    delta
Sysbench/SQL/3node/oltp_read_write-24              0.00           0.00         ~     (all equal)
ParallelSysbench/SQL/3node/oltp_read_write-24      0.01 ±62%      0.01 ±46%    ~     (p=0.930 n=20+20)

name                                           old alloc/op   new alloc/op   delta
Sysbench/SQL/3node/oltp_read_write-24            1.34MB ± 6%    1.33MB ± 6%    ~     (p=0.779 n=20+20)
ParallelSysbench/SQL/3node/oltp_read_write-24    1.31MB ± 6%    1.36MB ± 6%  +3.45%  (p=0.001 n=20+20)

name                                           old allocs/op  new allocs/op  delta
Sysbench/SQL/3node/oltp_read_write-24             5.79k ± 2%     5.81k ± 2%    ~     (p=0.317 n=20+20)
ParallelSysbench/SQL/3node/oltp_read_write-24     5.70k ± 1%     5.72k ± 1%    ~     (p=0.101 n=19+19)

wrote merged cpu profile to:
  old=benchdiff/af82767/artifacts/profiles/merged/cpu.prof
  new=benchdiff/2a00e41/artifacts/profiles/merged/cpu.prof

wrote merged mem profile to:
  old=benchdiff/af82767/artifacts/profiles/merged/mem.pb.gz
  new=benchdiff/2a00e41/artifacts/profiles/merged/mem.pb.gz

wrote merged mem_ParallelSysbench_SQL_3node_oltp_read_write.pb.gz profile to:
  old=benchdiff/af82767/artifacts/profiles/merged/mem_ParallelSysbench_SQL_3node_oltp_read_write.pb.gz
  new=benchdiff/2a00e41/artifacts/profiles/merged/mem_ParallelSysbench_SQL_3node_oltp_read_write.pb.gz

wrote merged mem_Sysbench_SQL_3node_oltp_read_write.pb.gz profile to:
  old=benchdiff/af82767/artifacts/profiles/merged/mem_Sysbench_SQL_3node_oltp_read_write.pb.gz
  new=benchdiff/2a00e41/artifacts/profiles/merged/mem_Sysbench_SQL_3node_oltp_read_write.pb.gz

@shubhamdhama
Copy link
Copy Markdown
Contributor Author

shubhamdhama commented May 19, 2026

Multiplexing disabled

> benchdiff -b --old (git rev-parse HEAD^) -c 20 -d 1000x ./pkg/sql/tests -r Sysbench/SQL/3node/oltp_read_write
old:  c5041d3 do-not-merge: enable DRPC
new:  4f20069 rpc: wire up DRPC stream multiplexing behind an en
args: benchdiff "-b" "--old" "c5041d30a31086b50a29124d0edbaf1df09e108b" "-c" "20" "-d" "1000x" "./pkg/sql/tests" "-r" "Sysbench/SQL/3node/oltp_read_write"

name                                           old time/op    new time/op    delta
ParallelSysbench/SQL/3node/oltp_read_write-24     852µs ± 6%     840µs ± 5%    ~     (p=0.055 n=20+18)
Sysbench/SQL/3node/oltp_read_write-24            13.1ms ± 4%    13.7ms ± 2%  +4.49%  (p=0.000 n=20+15)

name                                           old errs/op    new errs/op    delta
Sysbench/SQL/3node/oltp_read_write-24              0.00           0.00         ~     (all equal)
ParallelSysbench/SQL/3node/oltp_read_write-24      0.01 ±61%      0.01 ±64%    ~     (p=0.469 n=20+19)

name                                           old alloc/op   new alloc/op   delta
Sysbench/SQL/3node/oltp_read_write-24            1.32MB ± 5%    1.32MB ± 4%    ~     (p=0.358 n=20+20)
ParallelSysbench/SQL/3node/oltp_read_write-24    1.36MB ± 7%    1.37MB ± 7%    ~     (p=0.429 n=20+20)

name                                           old allocs/op  new allocs/op  delta
ParallelSysbench/SQL/3node/oltp_read_write-24     5.94k ± 2%     5.79k ± 3%  -2.60%  (p=0.001 n=18+20)
Sysbench/SQL/3node/oltp_read_write-24             5.72k ± 0%     5.77k ± 2%  +0.81%  (p=0.015 n=19+20)

Multiplexing enabled

> benchdiff -b --old (git rev-parse HEAD^) -c 20 -d 1000x ./pkg/sql/tests -r Sysbench/SQL/3node/oltp_read_write
old:  c5041d3 do-not-merge: enable DRPC
new:  d7188c5 rpc: wire up DRPC stream multiplexing behind an en
args: benchdiff "-b" "--old" "c5041d30a31086b50a29124d0edbaf1df09e108b" "-c" "20" "-d" "1000x" "./pkg/sql/tests" "-r" "Sysbench/SQL/3node/oltp_read_write"

building benchmark binaries for d7188c5: rpc: wire up DRPC stream multiplexing behind an en [bazel=true] 1/1 |
name                                           old time/op    new time/op    delta
Sysbench/SQL/3node/oltp_read_write-24            12.9ms ± 4%    13.3ms ± 3%  +2.57%  (p=0.001 n=20+20)
ParallelSysbench/SQL/3node/oltp_read_write-24     860µs ± 5%     903µs ± 6%  +5.04%  (p=0.000 n=20+20)

name                                           old errs/op    new errs/op    delta
Sysbench/SQL/3node/oltp_read_write-24              0.00           0.00         ~     (all equal)
ParallelSysbench/SQL/3node/oltp_read_write-24      0.00 ±27%      0.01 ±75%    ~     (p=0.082 n=14+20)

name                                           old alloc/op   new alloc/op   delta
Sysbench/SQL/3node/oltp_read_write-24            1.31MB ± 7%    1.30MB ± 6%    ~     (p=0.429 n=20+20)
ParallelSysbench/SQL/3node/oltp_read_write-24    1.36MB ± 6%    1.41MB ± 6%  +3.67%  (p=0.003 n=20+20)

name                                           old allocs/op  new allocs/op  delta
Sysbench/SQL/3node/oltp_read_write-24             5.72k ± 0%     5.75k ± 2%    ~     (p=0.091 n=18+20)
ParallelSysbench/SQL/3node/oltp_read_write-24     5.95k ± 5%     5.92k ± 1%    ~     (p=0.512 n=20+17)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge bors won't merge a PR with this label.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants