Skip to content

Commit

Permalink
benchmarks: apmbench SetMemoryLimit so benchmarks do not go OOM (#14257)
Browse files Browse the repository at this point in the history
  • Loading branch information
1pkg authored Oct 4, 2024
1 parent 23a0b0d commit 59e9076
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions systemtest/cmd/apmbench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"flag"
"fmt"
"log"
"runtime/debug"
"testing"
"time"

Expand All @@ -30,6 +31,7 @@ import (
"golang.org/x/time/rate"

"github.com/elastic/apm-server/systemtest/benchtest"
"github.com/elastic/go-sysinfo"
)

func Benchmark1000Transactions(b *testing.B, l *rate.Limiter) {
Expand Down Expand Up @@ -138,6 +140,11 @@ func Benchmark10000AggregationGroups(b *testing.B, l *rate.Limiter) {

func main() {
flag.Parse()
bytes, err := sysMemory()
if err != nil {
log.Fatal(err)
}
debug.SetMemoryLimit(int64(float64(bytes) * 0.9))
if err := benchtest.Run(
Benchmark1000Transactions,
BenchmarkOTLPTraces,
Expand All @@ -151,3 +158,15 @@ func main() {
log.Fatal(err)
}
}

func sysMemory() (uint64, error) {
host, err := sysinfo.Host()
if err != nil {
return 0, err
}
mem, err := host.Memory()
if err != nil {
return 0, err
}
return mem.Total, nil
}

0 comments on commit 59e9076

Please sign in to comment.