Skip to content

Commit d9fbcc3

Browse files
committed
sqlstats: fix insights benchmark bugs
- Transactions slice length was incorrectly initialized. - Transactions needed to set a UUID in order to get observed by the `observeTransaction` function and actually trigger the code that's being benchmarked. - Indexing into the `transactions` slice in the benchmark was incorrectly using `idx` instead of `i` and grabbing empty objects. Resolves: #151300 Epic: None Release note: None
1 parent 91a2138 commit d9fbcc3

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

cpu.out

11.6 KB
Binary file not shown.

pkg/sql/sqlstats/insights/insights_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/cockroachdb/cockroach/pkg/sql/sqlstats/insights"
2121
"github.com/cockroachdb/cockroach/pkg/util/stop"
2222
"github.com/cockroachdb/cockroach/pkg/util/uint128"
23+
"github.com/cockroachdb/cockroach/pkg/util/uuid"
2324
)
2425

2526
// Here we benchmark the entire insights stack, so that we can include in our
@@ -51,7 +52,7 @@ func BenchmarkInsights(b *testing.B) {
5152
var sessions sync.WaitGroup
5253
sessions.Add(numSessions)
5354
statements := make([]sqlstats.RecordedStmtStats, b.N)
54-
transactions := make([]sqlstats.RecordedTxnStats, b.N)
55+
transactions := make([]sqlstats.RecordedTxnStats, numSessions)
5556
for i := 0; i < numSessions; i++ {
5657
sessionID := clusterunique.ID{Uint128: uint128.FromInts(rand.Uint64(), uint64(i))}
5758
for j := 0; j < numTransactionsPerSession; j++ {
@@ -66,7 +67,8 @@ func BenchmarkInsights(b *testing.B) {
6667
}
6768
}
6869
transactions[i] = sqlstats.RecordedTxnStats{
69-
SessionID: sessionID,
70+
SessionID: sessionID,
71+
TransactionID: uuid.MakeV4(),
7072
}
7173
}
7274

@@ -76,7 +78,7 @@ func BenchmarkInsights(b *testing.B) {
7678
defer sessions.Done()
7779
for j := 0; j < numTransactionsPerSession; j++ {
7880
idx := numTransactionsPerSession*i + j
79-
provider.ObserveTransaction(ctx, &transactions[idx],
81+
provider.ObserveTransaction(ctx, &transactions[i],
8082
[]*sqlstats.RecordedStmtStats{&statements[idx]})
8183
}
8284
}(i)

0 commit comments

Comments
 (0)