From da67bcbd35557cdde74e6efde7e121c37b755795 Mon Sep 17 00:00:00 2001 From: Abdullah Gharaibeh Date: Tue, 3 Dec 2019 19:16:36 -0500 Subject: [PATCH] added benchmarks for preferred (anti)pod affinity --- .../scheduler_perf/scheduler_bench_test.go | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/test/integration/scheduler_perf/scheduler_bench_test.go b/test/integration/scheduler_perf/scheduler_bench_test.go index be231c71782..80cc98cfd0e 100644 --- a/test/integration/scheduler_perf/scheduler_bench_test.go +++ b/test/integration/scheduler_perf/scheduler_bench_test.go @@ -191,6 +191,44 @@ func BenchmarkSchedulingPodAffinity(b *testing.B) { } } +// BenchmarkSchedulingPreferredPodAffinity benchmarks the scheduling rate of pods with +// preferred PodAffinity rules when the cluster has various quantities of nodes and +// scheduled pods. +func BenchmarkSchedulingPreferredPodAffinity(b *testing.B) { + testBasePod := makeBasePodWithPreferredPodAffinity( + map[string]string{"foo": ""}, + map[string]string{"foo": ""}, + ) + // The test strategy creates pods with affinity for each other. + testStrategy := testutils.NewCustomCreatePodStrategy(testBasePod) + nodeStrategy := testutils.NewLabelNodePrepareStrategy(v1.LabelZoneFailureDomain, "zone1") + for _, test := range tests { + name := fmt.Sprintf("%vNodes/%vPods", test.nodes, test.existingPods) + b.Run(name, func(b *testing.B) { + benchmarkScheduling(test.nodes, test.existingPods, test.minPods, nodeStrategy, testStrategy, b) + }) + } +} + +// BenchmarkSchedulingPreferredPodAntiAffinity benchmarks the scheduling rate of pods with +// preferred PodAntiAffinity rules when the cluster has various quantities of nodes and +// scheduled pods. +func BenchmarkSchedulingPreferredPodAntiAffinity(b *testing.B) { + testBasePod := makeBasePodWithPreferredPodAntiAffinity( + map[string]string{"foo": ""}, + map[string]string{"foo": ""}, + ) + // The test strategy creates pods with affinity for each other. + testStrategy := testutils.NewCustomCreatePodStrategy(testBasePod) + nodeStrategy := testutils.NewLabelNodePrepareStrategy(v1.LabelZoneFailureDomain, "zone1") + for _, test := range tests { + name := fmt.Sprintf("%vNodes/%vPods", test.nodes, test.existingPods) + b.Run(name, func(b *testing.B) { + benchmarkScheduling(test.nodes, test.existingPods, test.minPods, nodeStrategy, testStrategy, b) + }) + } +} + // BenchmarkSchedulingNodeAffinity benchmarks the scheduling rate of pods with // NodeAffinity rules when the cluster has various quantities of nodes and // scheduled pods. @@ -232,6 +270,62 @@ func makeBasePodWithPodAntiAffinity(podLabels, affinityLabels map[string]string) return basePod } +// makeBasePodWithPreferredPodAntiAffinity creates a Pod object to be used as a template. +// The Pod has a preferred PodAntiAffinity with pods with the given labels. +func makeBasePodWithPreferredPodAntiAffinity(podLabels, affinityLabels map[string]string) *v1.Pod { + basePod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + GenerateName: "preferred-affinity-pod-", + Labels: podLabels, + }, + Spec: testutils.MakePodSpec(), + } + basePod.Spec.Affinity = &v1.Affinity{ + PodAntiAffinity: &v1.PodAntiAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{ + { + PodAffinityTerm: v1.PodAffinityTerm{ + LabelSelector: &metav1.LabelSelector{ + MatchLabels: affinityLabels, + }, + TopologyKey: v1.LabelHostname, + }, + Weight: 1, + }, + }, + }, + } + return basePod +} + +// makeBasePodWithPreferredPodAffinity creates a Pod object to be used as a template. +// The Pod has a preferred PodAffinity with pods with the given labels. +func makeBasePodWithPreferredPodAffinity(podLabels, affinityLabels map[string]string) *v1.Pod { + basePod := &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + GenerateName: "preferred-affinity-pod-", + Labels: podLabels, + }, + Spec: testutils.MakePodSpec(), + } + basePod.Spec.Affinity = &v1.Affinity{ + PodAffinity: &v1.PodAffinity{ + PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{ + { + PodAffinityTerm: v1.PodAffinityTerm{ + LabelSelector: &metav1.LabelSelector{ + MatchLabels: affinityLabels, + }, + TopologyKey: v1.LabelHostname, + }, + Weight: 1, + }, + }, + }, + } + return basePod +} + // makeBasePodWithPodAffinity creates a Pod object to be used as a template. // The Pod has a PodAffinity requirement against pods with the given labels. func makeBasePodWithPodAffinity(podLabels, affinityZoneLabels map[string]string) *v1.Pod {