Skip to content

Commit 8c760de

Browse files
committed
bench/tpcc: run each mix on its own cluster
Each run of a benchmark is now run in its own cluster to make each run independent of each other and avoid skewing results. Release note: None
1 parent 0437abf commit 8c760de

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

pkg/bench/tpcc/bench_test.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ var profileFlag = flag.String("profile", "",
6666
func BenchmarkTPCC(b *testing.B) {
6767
defer log.Scope(b).Close(b)
6868

69-
// Setup the cluster once for all benchmarks.
70-
ctx := context.Background()
71-
tc, pgURLs := startCluster(b, ctx)
72-
defer tc.Stopper().Stop(ctx)
73-
7469
for _, impl := range []struct{ name, flag string }{
7570
{"literal", "--literal-implementation=true"},
7671
{"optimized", "--literal-implementation=false"},
@@ -84,9 +79,37 @@ func BenchmarkTPCC(b *testing.B) {
8479
{"stock_level", "--mix=stockLevel=1"},
8580
{"default", "--mix=newOrder=10,payment=10,orderStatus=1,delivery=1,stockLevel=1"},
8681
} {
82+
var tc serverutils.TestClusterInterface
83+
var pgURLs [nodes]string
8784
b.Run(mix.name, func(b *testing.B) {
85+
ctx := context.Background()
86+
// TODO(mgartner): This is a hack to avoid repeatedly
87+
// setting up the cluster for a single benchmark run. Go's
88+
// benchmarking tooling will run a benchmark with b.N=1
89+
// first, and ramp up b.N until the benchmark hits a time
90+
// threshold. This means that the setup code will run
91+
// multiple times for a single benchmark result. To avoid
92+
// the high latency this would incur, we only run the setup
93+
// code when on the first execution of each iteration of the
94+
// benchmark, when b.N=1. If the benchmark is run with
95+
// --count greater than 1, then b.N will be reset to 1 for
96+
// each iteration, and a new cluster will be created,
97+
// ensuring benchmark results across interations remain
98+
// independent. This won't be necessary in Go 1.24+ when
99+
// b.Loop can be used instead.
100+
if b.N == 1 && tc != nil {
101+
tc.Stopper().Stop(ctx)
102+
tc = nil
103+
}
104+
// Setup the cluster.
105+
if tc == nil {
106+
tc, pgURLs = startCluster(b, ctx)
107+
}
88108
run(b, ctx, pgURLs, []string{impl.flag, mix.flag})
89109
})
110+
if tc != nil {
111+
tc.Stopper().Stop(context.Background())
112+
}
90113
}
91114
})
92115
}

0 commit comments

Comments
 (0)