Repository navigation
perf(txn): drop redundant client.mu lock in closeTxn success path - #25490
Conversation
aptend
left a comment
There was a problem hiding this comment.
Reviewed the multi-CN / invalid-CN unhappy path as well. I do not see a correctness dependency on the removed client.mu lock: client.mu is local to the txnClient, markAllActiveTxnAborted only does a non-blocking send to abortC, active txn traversal/removal is protected by the sharded active-txn locks, and new txn creation is gated by waitMarkAllActiveAbortedC in the async handler rather than by this close-path lock.
One small non-blocking note: the new comment says the ordering ensures this txn is still marked while it remains in the active map. Since the abort signal is asynchronous, this preserves the original signal-before-remove ordering, but it does not strictly guarantee the closing txn will be included in the later traversal. That is fine for correctness here, but the wording could be softened to avoid overclaiming.
pkg/txn/client tests passed locally: go test ./pkg/txn/client
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed latest head a7d7a38.
I do not see a correctness dependency on the removed first client.mu lock. markAllActiveTxnAborted is only a non-blocking abortC signal; active txn add/remove/iteration are protected by the sharded active-txn locks; user counters and wait queues still stay under client.mu; new txn creation is gated by waitMarkAllActiveAbortedC in the async abort-all handler. The mark-before-remove ordering is preserved, and the old lock did not make the async traversal include the closing txn either.
CI is green. Non-blocking: the new comment could be softened around "this txn is still marked" because the abort signal is asynchronous, but I do not think this blocks the PR.
a7d7a38 to
10344ad
Compare
closeTxn acquired client.mu twice (client.go:676 and 689). The first Lock/Unlock only "protected" markAllActiveTxnAborted, but that function just sends a non-blocking signal to abortC and does not touch client.mu. Every normal txn close paid for this redundant lock. Under sysbench oltp_point_select 1000vu, this pair accounted for 706s of mutex wait (51.62% of closeLocked cum). Removing it: - mutex total wait: 5909s -> 2030s (-66%) - sync.Mutex.Unlock: 3918s -> 769s (-80%) - p95 latency: 173ms -> 142ms (-18%) - TPS: 18555 -> 18867 (+1.7%, CPU already saturated) Closes matrixorigin#25489 Co-Authored-By: Claude <[email protected]>
10344ad to
7d666b0
Compare
|
Updated the closeTxn comment to avoid overclaiming the asynchronous abort traversal. It now says we preserve the original signal-before-remove ordering, but correctness does not rely on the closing txn being observed by the later active-txn traversal. |
Merge Queue Status
This pull request spent 13 seconds in the queue, including 1 second running CI. Required conditions to merge
|
…trixorigin#25490) `txnClient.closeTxn` acquired `client.mu` twice (client.go:676 and 689). The first Lock/Unlock only "protected" `markAllActiveTxnAborted`, but that function just sends a non-blocking signal to `abortC` (client.go:838) and does not touch `client.mu` — so the first Lock/Unlock was dead weight that every normal txn close paid for. Under high-concurrency autocommit workloads (sysbench `oltp_point_select` 1000vu), this redundant lock pair accounted for 706s of mutex wait and 51.62% of `closeLocked` cum. Drop it; `removeActiveTxn` uses its own sharded lock, and the mark-before-remove ordering is preserved. Approved by: @aptend, @XuPeng-SH, @iamlinjunhong
…trixorigin#25490) `txnClient.closeTxn` acquired `client.mu` twice (client.go:676 and 689). The first Lock/Unlock only "protected" `markAllActiveTxnAborted`, but that function just sends a non-blocking signal to `abortC` (client.go:838) and does not touch `client.mu` — so the first Lock/Unlock was dead weight that every normal txn close paid for. Under high-concurrency autocommit workloads (sysbench `oltp_point_select` 1000vu), this redundant lock pair accounted for 706s of mutex wait and 51.62% of `closeLocked` cum. Drop it; `removeActiveTxn` uses its own sharded lock, and the mark-before-remove ordering is preserved. Approved by: @aptend, @XuPeng-SH, @iamlinjunhong
…trixorigin#25490) `txnClient.closeTxn` acquired `client.mu` twice (client.go:676 and 689). The first Lock/Unlock only "protected" `markAllActiveTxnAborted`, but that function just sends a non-blocking signal to `abortC` (client.go:838) and does not touch `client.mu` — so the first Lock/Unlock was dead weight that every normal txn close paid for. Under high-concurrency autocommit workloads (sysbench `oltp_point_select` 1000vu), this redundant lock pair accounted for 706s of mutex wait and 51.62% of `closeLocked` cum. Drop it; `removeActiveTxn` uses its own sharded lock, and the mark-before-remove ordering is preserved. Approved by: @aptend, @XuPeng-SH, @iamlinjunhong
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #25489
What this PR does / why we need it:
txnClient.closeTxnacquiredclient.mutwice (client.go:676 and 689). The first Lock/Unlock only "protected"markAllActiveTxnAborted, but that function just sends a non-blocking signal toabortC(client.go:838) and does not touchclient.mu— so the first Lock/Unlock was dead weight that every normal txn close paid for.Under high-concurrency autocommit workloads (sysbench
oltp_point_select1000vu), this redundant lock pair accounted for 706s of mutex wait and 51.62% ofcloseLockedcum. Drop it;removeActiveTxnuses its own sharded lock, and the mark-before-remove ordering is preserved.Verification
sysbench
oltp_point_select, 10 tables × 1M rows, 1000 vusers, 120s,--skip_trx=on --db-ps-mode=disable, mo-srv-129 standalone (64-core,GOMEMLIMIT=40000MiB), main commit2a008285e. Before = stock binary, After = this PR.TPS gain is modest because at 1000vu the CPU is already saturated (~50 cores); the win is in tail latency and lock overhead. Newly surfaced bottleneck:
fileservice.IOMerger(25% mutex cum) — next target.Repro:
mo-srv-129:/data/mo-prof/{run_bench.sh,fix_verify.sh}, profiles at/data/mo-prof/pprof/{1000vu,1000vu_fix}/.Non-goals
DeepCopyallocation (~150GB/30s at 1000vu) — separate issue, needs plan-cache hit-rate check first.fileservice.IOMergercontention — next iteration.