You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Task] Profile sysbench CPU/Memory/Mutex contention and analyze bottlenecks #25472
plan DeepCopy(P0 第二项):planCache 用 SQL 文本做 key,--db-ps-mode=disable 下随机 id 字面量导致命中率 0,每条 SQL 重新 build plan + DeepCopy。auto/prepared 命中后 sql/plan cum 12.79%→0.61%。非 MO bug,优化方向是 SQL normalize(feature)。
Merged on 2026-07-22. Final PR head: 713e2c52d2faf4638d3d579e00d1717eb6b44a75; squash merge commit: 56f2d4d234cb0dbc434d3464752d5b43a61c25a1.
The retired single-KindOption path now avoids the escaping SpanConfig allocation while preserving custom options, multi-option ordering, nil-context normalization, trace-context behavior, and the alternate provider path.
Fresh-data A/B/A measured TPS +0.45%, CPU/query -0.56%, alloc/query -3.86%, malloc/query -2.35%, and GC cycles/query -3.98%. The profile removed approximately 4.018 GB / 60s and 29.25M objects / 60s from NonRecordingTracer.Start without an equivalent allocation migration.
The throughput result is treated as neutral; the confirmed benefit is reduced allocation and GC churn.
Required PR CI passed, and the post-merge TKE sysbench check passed. The failed merge-update-moc / Update MOC check is a post-merge sync workflow and is not a code-regression signal for this PR.
This closes only the retired trace KindOption allocation sub-item. #25472 remains open as the umbrella profiling/optimization task for the remaining observability and workload-specific hotspots.
Activity
VioletQwQ-0 commentedon Jul 8, 2026
point_select
配置
2a008285e+ closeTxn 修复 perf(txn): drop redundant client.mu lock in closeTxn success path #25490oltp_point_select.lua,10 tables × 1M rows,1000vu,120sTPS / p95
--db-ps-mode=disable--db-ps-mode=auto(prepared)Profile(auto 1000vu,8GB cache)
CPU(53 核满载):
Syscall65.19% +sync.Mutex.Lock2.65% +gcmarknewobject2.48% +context.value2.27% +prometheus.observe2.19%。无单点热点(cache 命中,无 lz4/memmove/crc32)。Mutex(总等待 617562s):
sync.Mutex.Unlock88.75% +runtime.unlock10.98% +RWMutex.Unlock31.38% cum。调用链frontend.handleConn → doComQuery → executeStmtWithTxn,139k QPS 下 frontend 路径分布式锁(Session.mu/Routine/planCache 等),非单把锁,架构层天花板。Block(总阻塞 377106s):
selectgo61.17% +sync.Mutex.Lock30.91% +fdMutex.rwlock5.57%。子项结论
closeTxn 锁竞争(#25489 + PR #25490):
closeTxn第一次client.mu.Lock是废锁——markAllActiveTxnAborted只发abortCchannel 信号不碰锁,每条 autocommit 关闭 txn 都白排一次队。删除后 mutex 等待 -80%、p95 -18%。详见 #25489。plan DeepCopy(P0 第二项):
planCache用 SQL 文本做 key,--db-ps-mode=disable下随机 id 字面量导致命中率 0,每条 SQL 重新 build plan + DeepCopy。auto/prepared 命中后sql/plancum 12.79%→0.61%。非 MO bug,优化方向是 SQL normalize(feature)。SQLFlusher trace 分配(#25505):trace/ETL 导出路径
SQLFlusher.FlushBuffer每次新建 10MB buffer(DefaultWriterBufferSize),30s 分配 156GB,CPU 0.006% 但推高 GC。sync.Pool 和按buf.Len()预分配两方案均 TPS 退化(-18%/-20%),放弃。详见 #25505。Profile 位置
/data/mo-prof/pprof/{1000vu_bigcache_disable,1000vu_bigcache_auto}/VioletQwQ-0 commentedon Jul 8, 2026
read_write 摸底
配置
2a008285e+ closeTxn 修复 perf(txn): drop redundant client.mu lock in closeTxn success path #25490oltp_read_write.lua,10 tables × 1M rows,6 档 vuser,120sTPS
read_write 比 point_select 早饱和(500vu 撞墙),写路径瓶颈更重。
Profile(1000vu)
CPU:
Syscall613.33% +memmove11.53% +lz4.decodeBlock5.08% + GC ~16%(scanSpan7.56% +tryDeferToSpanScan5.20% +fpTracebackPartialExpand3.25%)。写 + raft + trace 产生大量垃圾,GC 压力高于 point_select。Mutex(总等待 9292s):
runtime.unlock82.52% +sync.Mutex.Unlock14.56% +RWMutex.Unlock12.18% cum。和 point_select 不同——read_write 锁竞争主导是 runtime 内部锁(GC/调度),非应用层 sync.Mutex。Block(总阻塞 18722 hrs,point_select 的 54 倍):
selectgo92.99% +fdMutex.rwlock5.61% +txn/rpc.handleTxnRequest45.61% cum(事务 RPC worker 等待)+morpc.remoteBackend.writeLoop1.72%。Alloc(1580GB/30s):
SQLFlusher156GB +reflect.unsafe_New111GB +dragonboat raft74GB +plan.DeepCopyExpr58GB +time.newTimer30GB。子项结论
SQLFlusher trace 分配(#25505):read_write 1000vu 下 SQLFlusher 156GB alloc,跨 workload 复现(point_select auto 151GB)。详见 #25505。
handleTxnRequest block(8539 hrs / 45.61%):line-level 归因确认是 worker pool 空闲等待,非瓶颈。block 全在
server.go:305的select等s.queue来请求(8539 hrs),实际处理req.exec()仅 535s(0.002%)。多 worker goroutine 累计空闲,不是排队等待,无 runnable starvation,不建 issue。内存泄漏检测(8GB cache,1000vu,压测前/中/后 heap)
无明显泄漏:压测中峰值分配在压测后被 GC 回收,before/after 稳定占用持平。after 略高(bytes.growSlice 72MB)属后台 ETL/trace 正常波动。注:单次 1000vu 无法触发长时间泄漏(如 #25198 系列 CN 事务泄漏),需长时间多轮压测验证。
Profile 位置
/data/mo-prof/pprof_rw/1000vu/(默认 cache 6 档 profile)+/data/mo-prof/pprof/rw_leak/(8GB cache 泄漏检测)VioletQwQ-0 commentedon Jul 8, 2026
阶段更新:clean point_select + SQLFlusher 跨 workload 复现
point_select clean rer跑
之前 point_select 表被
read_write的 delete/tombstone 污染,IsRowDeleted进入读取路径,影响了 point_select 归因。重新使用 clean 数据后结果提升:--db-ps-mode=disable--db-ps-mode=auto(prepared)clean auto 1000vu:avg 6.61ms,p95 27.17ms,CPU profile 1602.14s/30s ≈ 53.4 cores(64 CPU 机器上不是完全打满)。
clean auto 1000vu 当前瓶颈
不是单一 closeTxn 锁。
CPU 侧:
linux.Syscall695.06s / 5.93%,主要是结果包写回客户端。mallocgc14.56% cum,gcBgMarkWorker9.8% cum。TableScan/readutil/blockio有明显 cum 成本。Mutex 侧:
IsMOCtledSpan:338.65hrs / 69.63%trace.Start:308.91hrs / 63.51%txnClient.closeTxn:35.88hrs / 7.38%txnOperator.closeLocked:36.16hrs / 7.44%这说明 #25490 之前的 closeTxn 废锁已经不是主导;clean auto 的最大锁等待来自 trace control 读路径的全局 mutex。该发现已建 #25539,但由于 trace 正在整体删除,#25539 已关闭,仅保留 profile 证据作为背景。
SQLFlusher 分配(#25505)跨 workload 复现
SQLFlusher.FlushBuffer的固定 10MB buffer 分配在 clean point_select、read_only、insert 中都复现:line-level 均指向:
read_only/insert 1000vu 中,
fmt.Sprintf只有 4-6GB,conn.Exec只有 2-3GB,说明主因是每次 flush 固定申请 10MB escape buffer。下一步
point_select clean auto 1000vu。验收:SQLFlusher.FlushBuffer从 ~223GB 降到 GB 级或退出 top20,TPS/CPU 不回退。VioletQwQ-0 commentedon Jul 15, 2026
P1 allocation optimization update: PR #25701 / #25710
在 clean data、
1000vu point_select auto、disable-trace=true、8GB memory + 50GB disk SHARED cache 条件下,已完成两个相互独立的高频分配优化验证。PR #25701:复用 SELECT result columns
普通
SELECT返回路径原先会构造两次 result column:一次用于 MySQL protocol columns,一次用于Session.rs。该 PR 改为只构造一次并复用同一份 snapshot;SHOW COLUMNS、其他 computation wrapper 和非 SELECT 路径保持原逻辑。本地 microbenchmark:
即单次列构造路径约
-40.2% B/op、-33.3% allocs/op。mo-srv-129 fresh-data A/B/A:
GetResultColumnsFromPlan.func1alloc space 从3.02 GB/30s降到1.44 GB/30.7s,按时间归一化约下降 53%。TPS 和平均延迟保持中性,符合该 PR “减少 SELECT response allocation churn,不改变执行计划和查询语义”的目标。PR #25710:避免默认 transaction callback map/slice 分配
原实现每个新事务都会为两个 client-owned
ClosedEventcallback 创建 map/slice。该 PR 将 immutable default callbacks 存在txnClient,operator 只在添加 custom callback 时通过 copy-on-write 创建私有 map。本地 benchmark:
mo-srv-129 clean A/B/A:
AppendEventCallback原约2.65 GB/30s的热点在 patched alloc profile 中消失,未观察到等量分配迁移。default/custom 顺序、首错短路、commit/rollback close-once、operator 隔离、RestartTxn清理和 race 生命周期均有测试覆盖。当前结论
perf(frontend): reuse SELECT result columns (#25701)
perf(lockservice): shard active transaction holder (#25823)
perf(vector): compact varlen data in CopyBatch (#25824)
perf(vector): compact varlen data in CopyBatch (cherry-pick #25824) (#…
VioletQwQ-0 commentedon Jul 23, 2026
Post-merge update for #26026:
713e2c52d2faf4638d3d579e00d1717eb6b44a75; squash merge commit:56f2d4d234cb0dbc434d3464752d5b43a61c25a1.KindOptionpath now avoids the escapingSpanConfigallocation while preserving custom options, multi-option ordering, nil-context normalization, trace-context behavior, and the alternate provider path.+0.45%, CPU/query-0.56%, alloc/query-3.86%, malloc/query-2.35%, and GC cycles/query-3.98%. The profile removed approximately4.018 GB / 60sand29.25M objects / 60sfromNonRecordingTracer.Startwithout an equivalent allocation migration.merge-update-moc / Update MOCcheck is a post-merge sync workflow and is not a code-regression signal for this PR.This closes only the retired trace
KindOptionallocation sub-item. #25472 remains open as the umbrella profiling/optimization task for the remaining observability and workload-specific hotspots.perf(frontend): reuse SELECT result columns (matrixorigin#25701)
perf(lockservice): shard active transaction holder (matrixorigin#25823)
perf(vector): compact varlen data in CopyBatch (matrixorigin#25824)
perf(frontend): reuse SELECT result columns (matrixorigin#25701)
perf(lockservice): shard active transaction holder (matrixorigin#25823)
perf(vector): compact varlen data in CopyBatch (matrixorigin#25824)
perf(frontend): reuse SELECT result columns (matrixorigin#25701)
perf(lockservice): shard active transaction holder (matrixorigin#25823)
perf(vector): compact varlen data in CopyBatch (matrixorigin#25824)