Skip to content

feat(raft): 节点间 RPC 连接池(先量化 → 优化 → ShardKV 受益) - #232

Merged
NeverENG merged 1 commit into
mainfrom
feat/rpc-connection-pool
Aug 5, 2026
Merged

feat(raft): 节点间 RPC 连接池(先量化 → 优化 → ShardKV 受益)#232
NeverENG merged 1 commit into
mainfrom
feat/rpc-connection-pool

Conversation

@NeverENG

@NeverENG NeverENG commented Aug 5, 2026

Copy link
Copy Markdown
Owner

你说「链接池能做好优化吗,做好了就更新 shardkv」——按测量优先:先量化是不是真瓶颈,证实了再做,做好接进 ShardKV。

量化(measure-first)

BenchmarkRPC_*

场景 ns/op allocs/op
DialPerCall 串行 133,015 428
Pooled 串行 25,365 (5.2×↓) 16
DialPerCall 并发 65,459 428
Pooled 并发 5,293 (12.4×↓) 16

并发下差距拉大到 12×(多分片真实场景,dial-per-call 卡 TCP 握手)。瓶颈证实。

优化

rpcPool:每对端缓存复用一个 *rpc.Client(net/rpc Client 并发安全、单连接多路复用)。DialTimeout 拨号、ErrShutdown 重拨、callTimeout 支持 Propose 超时。包级共享池 → 每对端一条多路复用连接。

更新 ShardKV

Raft Send*/callPropose 改用池 → ShardKV 无需改动即受益Put→ProposeToGroup→callPropose→池;各分片组复制 Send*→池)。

验证

集群 + shardkv 测试全绿、-race 净、集群稳定 10/10、全仓 18 包全绿、零依赖不变。详见 docs/iteration-2026-08-05-rpc-connection-pool.md

🤖 Generated with Claude Code

先量化:dial-per-call vs 池,串行 5.2x、并发 12.4x(多分片真实场景),分配 428→16。
确认瓶颈后建 rpcPool:每对端缓存复用一个并发安全的 *rpc.Client,DialTimeout 拨号、ErrShutdown
重拨、callTimeout 支持 Propose 超时;包级共享池令每对端只一条多路复用连接。Raft Send*/callPropose
改用池,ShardKV 无需改动即受益(Put→ProposeToGroup→池,各组复制 Send*→池)。集群+shard+-race 全绿。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@NeverENG
NeverENG merged commit e2ee4be into main Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@NeverENG, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 13 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fd3ccf48-3fb5-46df-a3ec-b63876b2eaef

📥 Commits

Reviewing files that changed from the base of the PR and between 5023366 and 7a7dc24.

📒 Files selected for processing (5)
  • Raft/group_server.go
  • Raft/rpc.go
  • Raft/rpcpool.go
  • Raft/rpcpool_bench_test.go
  • docs/iteration-2026-08-05-rpc-connection-pool.md

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

🐯 BanGD 数据库内核评审

整体风险:🟡 中

变更总结:本 PR 将 Raft 节点间的 RPC 调用从「每次调用都 rpc.Dial+Call+Close」(每次一次 TCP 三次握手)改为连接池复用:新增 Raft/rpcpool.go,每对端地址缓存复用一个 net/rpc *rpc.Client(Client 本身并发安全,按 seq 号在单连接上多路复用并发调用),包级 defaultRPCPool 供所有 Raft 组共享。SendRequestVote/SendAppendEntries/SendInstallSnapshot/callPropose 全部改用池。含:net.DialTimeout 带超时拨号(优于原无超时的 rpc.Dial);ErrShutdown 时丢弃重拨重试一次;callTimeout 用 Go+select 支持 Propose 调用超时(超时不丢连接)。并附 benchmark 证明并发下连接池快 12.4×。这不改变 RPC 协议/磁盘格式/并发模型,仅替换传输层客户端连接管理。

本评审不阻塞合入;架构级建议以 Issue 形式跟踪,普通问题在下方内联列出。

架构问题(共 2 项)


本次评审消耗 token:共 103771 tokens(输入 87991,输出 4900,缓存命中 10880,缓存写入 0)|维度 [concurrency, memory, lock, storage, performance]|补充阅读周边文件 [Raft/raft.go]|对抗式复核 3 票/条,过滤疑似误报 0 条

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.

1 participant