Skip to content

Commit

Permalink
test: Add minValues to the NodePool requirements for benchmark testin…
Browse files Browse the repository at this point in the history
…g. (#1053)
  • Loading branch information
nikmohan123 committed Feb 29, 2024
1 parent 01b8127 commit 685ebfe
Showing 1 changed file with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package scheduling_test

import (
"context"
"flag"
"fmt"
"math"
"math/rand"
Expand All @@ -40,6 +41,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/logging"

"sigs.k8s.io/karpenter/pkg/apis/v1beta1"
"sigs.k8s.io/karpenter/pkg/cloudprovider"
"sigs.k8s.io/karpenter/pkg/cloudprovider/fake"
"sigs.k8s.io/karpenter/pkg/controllers/provisioning/scheduling"
Expand All @@ -59,6 +61,9 @@ var r = rand.New(rand.NewSource(42))
// To run the benchmarks use:
// `go test -tags=test_performance -run=XXX -bench=.`
//
// To run the benchmarks with minValues included in NodePool requirements, use:
// `go test -tags=test_performance -run=XXX -bench=. -minValues=true`
//
// to get something statistically significant for comparison we need to run them several times and then
// compare the results between the old performance and the new performance.
// ```sh
Expand Down Expand Up @@ -91,6 +96,12 @@ func BenchmarkScheduling5000(b *testing.B) {
benchmarkScheduler(b, 400, 5000)
}

var includeMinValues bool

func init() {
flag.BoolVar(&includeMinValues, "minValues", false, "include minValues in NodePool requirement")
}

// TestSchedulingProfile is used to gather profiling metrics, benchmarking is primarily done with standard
// Go benchmark functions
// go test -tags=test_performance -run=SchedulingProfile
Expand Down Expand Up @@ -124,15 +135,32 @@ func TestSchedulingProfile(t *testing.T) {
totalNodes += int(nodeCount)
}
}
fmt.Println("scheduled", totalPods, "against", totalNodes, "nodes in total in", totalTime, float64(totalPods)/totalTime.Seconds(), "pods/sec")
fmt.Println("scheduled", totalPods, "against", totalNodes, "nodes in total in", totalTime, "with minValues included", includeMinValues, float64(totalPods)/totalTime.Seconds(), "pods/sec")
tw.Flush()
}

func benchmarkScheduler(b *testing.B, instanceCount, podCount int) {
// disable logging
ctx = logging.WithLogger(context.Background(), zap.NewNop().Sugar())
nodePool := test.NodePool()

nodePoolWithMinValues := test.NodePool(v1beta1.NodePool{
Spec: v1beta1.NodePoolSpec{
Template: v1beta1.NodeClaimTemplate{
Spec: v1beta1.NodeClaimSpec{
Requirements: []v1beta1.NodeSelectorRequirementWithMinValues{
{
NodeSelectorRequirement: v1.NodeSelectorRequirement{
Key: v1.LabelInstanceTypeStable,
Operator: v1.NodeSelectorOpExists,
},
MinValues: lo.ToPtr(50), // Adding highest possible minValues and safest way to add it would be to instanceType requirement.
},
},
},
},
},
})
nodePoolWithoutMinValues := test.NodePool()
nodePool := lo.Ternary(includeMinValues, nodePoolWithMinValues, nodePoolWithoutMinValues)
instanceTypes := fake.InstanceTypes(instanceCount)
cloudProvider = fake.NewCloudProvider()
cloudProvider.InstanceTypes = instanceTypes
Expand Down

0 comments on commit 685ebfe

Please sign in to comment.