Skip to content

[Performance] trace.Start contends on global IsMOCtledSpan mutex under high-concurrency point_select #25539

Closed

Description

@VioletQwQ-0

Summary

High-concurrency sysbench point_select shows severe mutex contention in the trace control read path. The dominant mutex wait is not the txn close lock addressed by #25490; it is trace.Start repeatedly calling IsMOCtledSpan, which takes a global sync.Mutex for read-only access to mo_ctl controlled span configuration.

Workload

  • oltp_point_select 1000vu, --db-ps-mode=auto (prepared)
  • clean table/data after removing read_write tombstone pollution
  • file service cache: SHARED memory cache 8GB
  • standalone mo-srv-129, 64 CPUs, GOMEMLIMIT=40000MiB
  • Result: 150,941 TPS, avg 6.61ms, p95 27.17ms
  • CPU profile: 1602.14s samples / 30s = ~53.4 cores, so CPU is high but not fully saturated on 64 CPUs

Profile Evidence

Mutex profile: /data/mo-prof/pprof/1000vu_clean_auto/mutex.pprof

Total mutex delay: 486.38hrs

IsMOCtledSpan                         338.65hrs  69.63%
trace.Start                           308.91hrs  63.51%
sync.Mutex.Unlock                     410.50hrs  84.40% flat
txnClient.closeTxn                     35.88hrs   7.38%
txnOperator.closeLocked                36.16hrs   7.44%

Line-level evidence:

github.com/matrixorigin/matrixone/pkg/util/trace.IsMOCtledSpan
  338.65hrs cum, 69.63% of total mutex delay

config.go:210  MOCtledSpanEnableConfig.Lock()
config.go:211  defer MOCtledSpanEnableConfig.Unlock()
config.go:213  if state, exist := MOCtledSpanEnableConfig.KindToState[kind]; exist {
config.go:214      return true, state.Enable, state.Threshold
config.go:216  return false, false, 0

Current structure:

var MOCtledSpanEnableConfig struct {
    sync.Mutex
    NameToKind  map[string]SpanKind
    KindToState map[SpanKind]*MoCtledState
}

IsMOCtledSpan is a hot read path under high concurrency, while SetMoCtledSpanState is a rare control operation. A global exclusive mutex serializes all concurrent trace-start reads.

Impact

Suggested Direction

  • Replace the read path lock with RWMutex.RLock, or use atomic/copy-on-write configuration for mo_ctl span state.
  • Keep SetMoCtledSpanState write-side semantics safe.
  • Validate with mutex profile before/after under point_select clean auto 1000vu.

Acceptance

  • IsMOCtledSpan no longer dominates mutex delay in 1000vu_clean_auto.
  • No data race in trace control configuration.
  • TPS/latency do not regress.

Related profiling task: #25472.

Activity

  1. VioletQwQ-0 commented on Jul 8, 2026

    @VioletQwQ-0
    CollaboratorAuthor

    Closing this as covered by the ongoing broader trace removal work. The profile evidence is still valid and useful as context: under point_select clean auto 1000vu, IsMOCtledSpan accounted for ~338.65h / 69.63% of aggregate mutex delay. However, since the trace path itself is being removed, we do not need a separate targeted fix for this mutex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions