Repository navigation
Description
Summary
Under sysbench oltp_point_select at 1000 vusers, QPS saturates: 500vu→1000vu only +4% (17859→18555 qps) while average latency rises 28ms→54ms and p95 latency rises 130ms→174ms. Mutex profile shows the bottleneck is centralized client.mu contention in txnClient.closeTxn, invoked synchronously on every autocommit statement close.
Workload
- sysbench
oltp_point_select.lua, 10 tables × 1,000,000 rows --threads=1000 --time=120 --skip_trx=on --db-ps-mode=disable --auto_inc=off --create_secondary=off- MO standalone, 64-core,
GOMEMLIMIT=40000MiB, main (commit2a008285e)
Symptom
| vusers | TPS | avg lat | p95 lat |
|---|---|---|---|
| 100 | 11,955 | 8.4ms | 36.24ms |
| 500 | 17,859 | 28.0ms | 130.13ms |
| 1000 | 18,555 | 53.84ms | 173.58ms |
500→1000 vusers: TPS +4%, avg latency +92%, p95 latency +33%. Saturated.
Profile Evidence (1000vu mutex, 30s sample, total contention 1.64hrs)
flat flat% cum cum%
3918.80s 66.32% 3923.78s 66.40% sync.(*Mutex).Unlock (partial-inline)
1874.68s 31.73% 1874.68s 31.73% runtime.unlock
38.86s 0.66% 3853.33s 65.21% sync.(*RWMutex).Unlock
Call chain (focus=sync, cum):
frontend.executeStmtWithWorkspace
→ TxnHandler.Commit → txnOperator.closeLocked
→ triggerEventLocked(ClosedEvent) → txnClient.closeTxn → client.mu
Line-level attribution:
closeLocked(operator.go:1639)triggerEventLocked= 3050s / 51.62%closeTxn(client.go:684) firstclient.mu.Unlock()= 706s wait attribution- second
client.mu.Lock()(client.go:689) = 309ms — contention concentrates on the first lock segment
Root Cause
Every autocommit point select creates and closes a txn. The close path:
frontend.finishTxnFunc → Commit(txn.go:463) — every autocommit stmttxnOperator.closeLocked(operator.go:1616) — holdstc.mu, synchronously triggersClosedEventClosedEvent→txnClient.closeTxn(client.go:672) — contends on centralizedclient.mu
closeTxn acquires client.mu twice (client.go:676 and 689). The first Lock (676) only "protects" markAllActiveTxnAborted(), but that function just sends a non-blocking signal to client.abortC (client.go:838) and does not touch client.mu:
func (client *txnClient) markAllActiveTxnAborted() {
select {
case client.abortC <- time.Now():
default:
}
}So the first Lock/Unlock (676/684) is dead weight that every normal close pays for — and at 1000vu it accounts for 706s of mutex wait.
Suggested Fix
Drop the first client.mu Lock/Unlock — markAllActiveTxnAborted doesn't need it, and removeActiveTxn (client.go:254) uses its own sharded-map lock:
func (client *txnClient) closeTxn(ctx context.Context, txnOp TxnOperator, event TxnEvent, value any) (err error) {
txn := event.Txn
key := string(txn.ID)
if moerr.IsMoErrCode(event.Err, moerr.ErrCannotCommitOnInvalidCN) {
client.markAllActiveTxnAborted()
}
op, ok := client.removeActiveTxn(key)
client.mu.Lock()
// ... existing metrics / users-- / activate-waiters logic
}Validation: rerun 1000vu point_select, confirm mutex profile closeTxn first-segment delay (706s) is gone and TPS improves.
Reproduction
Profile at mo-srv-129:/data/mo-prof/pprof/1000vu/mutex.pprof; repro script at /data/mo-prof/run_bench.sh. Related profiling task: #25472.
Non-goals
- plan build
DeepCopyallocation (also surfaced, ~150GB/30s at 1000vu) — separate issue, needs plan-cache hit-rate check first. - GC pressure (scanSpan 5.8% at 1000vu) — downstream of allocation, addressed by the above.
Activity
perf(txn): drop redundant client.mu lock in closeTxn success path
perf(txn): drop redundant client.mu lock in closeTxn success path
VioletQwQ-0 commentedon Jul 13, 2026
Fixed by merged PR #25490: #25490. The redundant client.mu lock pair in the closeTxn path was removed and validated with reduced mutex wait and point_select tail latency.