perf(wal): storage WAL group commit——并发写共享一次 fsync#150
Conversation
standalone 写路径此前每条 Append 都 Write+Sync 一次,吞吐被单机 fsync 速率(本机 ~254 次/秒)死死封顶:50 并发 PUT 仅 225 qps、P50 203ms。 改为 group commit:所有 Append 投递到 reqCh,由唯一的 flushLoop 攒批—— 把当前排队的并发写一次写入后只 fsync 一次,再唤醒整批等待者。并发越高 摊销越充分。flushLoop 成为文件唯一写者,同时消除了原先无锁并发 Write+Sync 的隐患。持久化契约不变:Append 返回即代表该记录已随批 fsync 落盘;WAL 记录格式与 Replay/撕裂尾写处理保持不变。 实测(256B value,本机): c=50: 225 → 6087 qps(27x),P50 203ms → 8ms c=200: ~225 → 22231 qps(~99x),P50 8ms GET(纯内存)不受影响,仍 ~16.8k qps。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe WAL now queues concurrent appends for background group commits, syncing each batch once before completing requests. Shutdown drains pending requests before closing the file. A concurrent test validates replay of 500 appended records. ChangesWAL group commit
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant WAL
participant flushLoop
participant File
Client->>WAL: Append operation
WAL->>flushLoop: enqueue walReq
flushLoop->>File: writeRecord for batch
flushLoop->>File: Sync once
flushLoop-->>WAL: batch result
WAL-->>Client: return result
Possibly related issues
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
🐯 BanGD 数据库内核评审整体风险:🟡 中 变更总结:将 WAL 写入从每 Append 一次 fsync 改为 group commit 模型:Append 投递
架构问题(共 2 项)
普通问题(共 1 项)
本次评审消耗 token:共 63611 tokens(输入 59263,输出 4348,缓存命中 0,缓存写入 0)|维度 [concurrency, memory, storage, performance, resource]|对抗式复核 3 票/条,过滤疑似误报 0 条 |
背景
standalone 写路径此前每条
WAL.Append都Write+Sync一次,吞吐被单机 fsync 速率(本机 ~254 次/秒)死死封顶。实测层次对比(256B value,本机)
改动
WAL.Append投递请求到reqCh,唯一的flushLoop攒批:写完整批只fsync一次,再唤醒全部等待者。并发越高摊销越充分。flushLoop成为文件唯一写者,顺带消除原先无锁并发Write+Sync的隐患。Append返回即代表记录已随批 fsync 落盘;记录格式、Replay、撕裂尾写处理均保持不变。🤖 Generated with Claude Code
Summary by CodeRabbit
Performance Improvements
Reliability