Skip to content

Commit 61127a4

Browse files
committed
sqlstats: convert RWMutex to Mutex
This commit changes the RWMutex on the sql stats containers to the regular exclusive Mutex struct. The motivation behind this change is that RWMutex scales poorly with CPU count. See benchmarks below. Epic: none Part of: #140590 Release note: None
1 parent dc0abfb commit 61127a4

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

pkg/sql/sqlstats/ssmemstorage/ss_mem_iterator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func NewStmtStatsIterator(
3232
) StmtStatsIterator {
3333
var stmtKeys stmtList
3434
func() {
35-
container.mu.RLock()
36-
defer container.mu.RUnlock()
35+
container.mu.Lock()
36+
defer container.mu.Unlock()
3737
for k := range container.mu.stmts {
3838
stmtKeys = append(stmtKeys, k)
3939
}

pkg/sql/sqlstats/ssmemstorage/ss_mem_storage.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type Container struct {
6969
uniqueServerCount *SQLStatsAtomicCounters
7070

7171
mu struct {
72-
syncutil.RWMutex
72+
syncutil.Mutex
7373

7474
// acc is the memory account that tracks memory allocations related to stmts
7575
// and txns within this Container struct.
@@ -431,8 +431,8 @@ func (s *stmtStats) mergeStatsLocked(statistics *appstatspb.CollectedStatementSt
431431

432432
// getStatsForStmtWithKey returns an instance of stmtStats.
433433
func (s *Container) getStatsForStmtWithKey(key stmtKey) (stats *stmtStats) {
434-
s.mu.RLock()
435-
defer s.mu.RUnlock()
434+
s.mu.Lock()
435+
defer s.mu.Unlock()
436436
stats = s.mu.stmts[key]
437437
return stats
438438
}
@@ -480,8 +480,8 @@ func (s *Container) tryCreateStatsForStmtWithKeyLocked(
480480
}
481481

482482
func (s *Container) getStatsForTxnWithKey(key appstatspb.TransactionFingerprintID) *txnStats {
483-
s.mu.RLock()
484-
defer s.mu.RUnlock()
483+
s.mu.Lock()
484+
defer s.mu.Unlock()
485485
return s.mu.txns[key]
486486
}
487487

pkg/sql/sqlstats/ssmemstorage/ss_mem_writer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ func (s *Container) StatementSampled(fingerprint string, implicitTxn bool, datab
163163
implicitTxn: implicitTxn,
164164
database: database,
165165
}
166-
s.mu.RLock()
167-
defer s.mu.RUnlock()
166+
s.mu.Lock()
167+
defer s.mu.Unlock()
168168
_, ok := s.mu.sampledStatementCache[key]
169169
return ok
170170
}

0 commit comments

Comments
 (0)