Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions central/alert/datastore/internal/store/postgres/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package postgres
import (
"context"
"fmt"
"runtime"
"testing"
"time"

"github.com/stackrox/rox/generated/storage"
"github.com/stackrox/rox/pkg/postgres/pgtest"
Expand Down Expand Up @@ -39,12 +41,27 @@ func BenchmarkMany(b *testing.B) {

for n := 1; n < alertsNum; n = n * 2 {
b.Run(fmt.Sprintf("upsert %d alerts", n), func(b *testing.B) {
startHeap, startHeapObj := getHeapAllocAndObjects(0, 0)
var maxHeap uint64
var maxHeapObj uint64
ticker := time.NewTicker(10 * time.Millisecond)
go func() {
for range ticker.C {
maxHeap, maxHeapObj = getHeapAllocAndObjects(maxHeap, maxHeapObj)
}
}()

for b.Loop() {
err := store.UpsertMany(ctx, alerts[:n])
if err != nil {
b.Fatal(err)
}
}
ticker.Stop()
b.ReportMetric(float64(maxHeap-startHeap), "max_heap_bytes")
b.ReportMetric(float64(maxHeapObj-startHeapObj), "max_heap_objects")
Comment thread
janisz marked this conversation as resolved.
b.ReportMetric(float64(startHeap), "start_heap_bytes")
b.ReportMetric(float64(startHeapObj), "start_heap_objects")
})
b.Run(fmt.Sprintf("get %d alerts", n), func(b *testing.B) {
for b.Loop() {
Expand All @@ -71,3 +88,12 @@ func BenchmarkMany(b *testing.B) {
})
}
}

func getHeapAllocAndObjects(maxHeap uint64, maxHeapObj uint64) (uint64, uint64) {
runtime.GC()
var m runtime.MemStats
runtime.ReadMemStats(&m)
maxHeap = max(maxHeap, m.HeapAlloc)
maxHeapObj = max(maxHeapObj, m.HeapObjects)
return maxHeap, maxHeapObj
}
Loading