Set a minimum b.N for scheduler_perf benchmarks.

Under the default behavior of Go benchmark tests, all our scheduler_perf
benchmark tests run with b.N=1, which is lower than we would like. This
adds a lower bound to b.N so that the results are more meaningful.

The alternative to this change is to always run these tests with the
-benchtime flag set to a duration which will force b.N to increase. That
would cause any test setup to be executed repeatedly as b.N ramps up,
and -timout would probably also need to be set higher.
This commit is contained in:
Jonathan Basseri
2017-12-18 11:19:15 -08:00
parent 2f1408ebf7
commit 3a456bf9cb

View File

@@ -31,22 +31,25 @@ import (
// BenchmarkScheduling benchmarks the scheduling rate when the cluster has
// various quantities of nodes and scheduled pods.
func BenchmarkScheduling(b *testing.B) {
tests := []struct{ nodes, pods int }{
{nodes: 100, pods: 0},
{nodes: 100, pods: 1000},
{nodes: 1000, pods: 0},
{nodes: 1000, pods: 1000},
tests := []struct{ nodes, pods, minOps int }{
{nodes: 100, pods: 0, minOps: 100},
{nodes: 100, pods: 1000, minOps: 100},
{nodes: 1000, pods: 0, minOps: 100},
{nodes: 1000, pods: 1000, minOps: 100},
}
for _, test := range tests {
name := fmt.Sprintf("%vNodes/%vPods", test.nodes, test.pods)
b.Run(name, func(b *testing.B) { benchmarkScheduling(test.nodes, test.pods, b) })
b.Run(name, func(b *testing.B) { benchmarkScheduling(test.nodes, test.pods, test.minOps, b) })
}
}
// benchmarkScheduling benchmarks scheduling rate with specific number of nodes
// and specific number of pods already scheduled. Since an operation takes relatively
// long time, b.N should be small: 10 - 100.
func benchmarkScheduling(numNodes, numScheduledPods int, b *testing.B) {
// and specific number of pods already scheduled.
// Since an operation typically takes more than 1 second, we put a minimum bound on b.N of minOps.
func benchmarkScheduling(numNodes, numScheduledPods, minOps int, b *testing.B) {
if b.N < minOps {
b.N = minOps
}
schedulerConfigFactory, finalFunc := mustSetupScheduler()
defer finalFunc()
c := schedulerConfigFactory.GetClient()