@@ -191,6 +191,44 @@ func BenchmarkSchedulingPodAffinity(b *testing.B) {
191
191
}
192
192
}
193
193
194
+ // BenchmarkSchedulingPreferredPodAffinity benchmarks the scheduling rate of pods with
195
+ // preferred PodAffinity rules when the cluster has various quantities of nodes and
196
+ // scheduled pods.
197
+ func BenchmarkSchedulingPreferredPodAffinity (b * testing.B ) {
198
+ testBasePod := makeBasePodWithPreferredPodAffinity (
199
+ map [string ]string {"foo" : "" },
200
+ map [string ]string {"foo" : "" },
201
+ )
202
+ // The test strategy creates pods with affinity for each other.
203
+ testStrategy := testutils .NewCustomCreatePodStrategy (testBasePod )
204
+ nodeStrategy := testutils .NewLabelNodePrepareStrategy (v1 .LabelZoneFailureDomain , "zone1" )
205
+ for _ , test := range tests {
206
+ name := fmt .Sprintf ("%vNodes/%vPods" , test .nodes , test .existingPods )
207
+ b .Run (name , func (b * testing.B ) {
208
+ benchmarkScheduling (test .nodes , test .existingPods , test .minPods , nodeStrategy , testStrategy , b )
209
+ })
210
+ }
211
+ }
212
+
213
+ // BenchmarkSchedulingPreferredPodAntiAffinity benchmarks the scheduling rate of pods with
214
+ // preferred PodAntiAffinity rules when the cluster has various quantities of nodes and
215
+ // scheduled pods.
216
+ func BenchmarkSchedulingPreferredPodAntiAffinity (b * testing.B ) {
217
+ testBasePod := makeBasePodWithPreferredPodAntiAffinity (
218
+ map [string ]string {"foo" : "" },
219
+ map [string ]string {"foo" : "" },
220
+ )
221
+ // The test strategy creates pods with affinity for each other.
222
+ testStrategy := testutils .NewCustomCreatePodStrategy (testBasePod )
223
+ nodeStrategy := testutils .NewLabelNodePrepareStrategy (v1 .LabelZoneFailureDomain , "zone1" )
224
+ for _ , test := range tests {
225
+ name := fmt .Sprintf ("%vNodes/%vPods" , test .nodes , test .existingPods )
226
+ b .Run (name , func (b * testing.B ) {
227
+ benchmarkScheduling (test .nodes , test .existingPods , test .minPods , nodeStrategy , testStrategy , b )
228
+ })
229
+ }
230
+ }
231
+
194
232
// BenchmarkSchedulingNodeAffinity benchmarks the scheduling rate of pods with
195
233
// NodeAffinity rules when the cluster has various quantities of nodes and
196
234
// scheduled pods.
@@ -232,6 +270,62 @@ func makeBasePodWithPodAntiAffinity(podLabels, affinityLabels map[string]string)
232
270
return basePod
233
271
}
234
272
273
+ // makeBasePodWithPreferredPodAntiAffinity creates a Pod object to be used as a template.
274
+ // The Pod has a preferred PodAntiAffinity with pods with the given labels.
275
+ func makeBasePodWithPreferredPodAntiAffinity (podLabels , affinityLabels map [string ]string ) * v1.Pod {
276
+ basePod := & v1.Pod {
277
+ ObjectMeta : metav1.ObjectMeta {
278
+ GenerateName : "preferred-affinity-pod-" ,
279
+ Labels : podLabels ,
280
+ },
281
+ Spec : testutils .MakePodSpec (),
282
+ }
283
+ basePod .Spec .Affinity = & v1.Affinity {
284
+ PodAntiAffinity : & v1.PodAntiAffinity {
285
+ PreferredDuringSchedulingIgnoredDuringExecution : []v1.WeightedPodAffinityTerm {
286
+ {
287
+ PodAffinityTerm : v1.PodAffinityTerm {
288
+ LabelSelector : & metav1.LabelSelector {
289
+ MatchLabels : affinityLabels ,
290
+ },
291
+ TopologyKey : v1 .LabelHostname ,
292
+ },
293
+ Weight : 1 ,
294
+ },
295
+ },
296
+ },
297
+ }
298
+ return basePod
299
+ }
300
+
301
+ // makeBasePodWithPreferredPodAffinity creates a Pod object to be used as a template.
302
+ // The Pod has a preferred PodAffinity with pods with the given labels.
303
+ func makeBasePodWithPreferredPodAffinity (podLabels , affinityLabels map [string ]string ) * v1.Pod {
304
+ basePod := & v1.Pod {
305
+ ObjectMeta : metav1.ObjectMeta {
306
+ GenerateName : "preferred-affinity-pod-" ,
307
+ Labels : podLabels ,
308
+ },
309
+ Spec : testutils .MakePodSpec (),
310
+ }
311
+ basePod .Spec .Affinity = & v1.Affinity {
312
+ PodAffinity : & v1.PodAffinity {
313
+ PreferredDuringSchedulingIgnoredDuringExecution : []v1.WeightedPodAffinityTerm {
314
+ {
315
+ PodAffinityTerm : v1.PodAffinityTerm {
316
+ LabelSelector : & metav1.LabelSelector {
317
+ MatchLabels : affinityLabels ,
318
+ },
319
+ TopologyKey : v1 .LabelHostname ,
320
+ },
321
+ Weight : 1 ,
322
+ },
323
+ },
324
+ },
325
+ }
326
+ return basePod
327
+ }
328
+
235
329
// makeBasePodWithPodAffinity creates a Pod object to be used as a template.
236
330
// The Pod has a PodAffinity requirement against pods with the given labels.
237
331
func makeBasePodWithPodAffinity (podLabels , affinityZoneLabels map [string ]string ) * v1.Pod {
0 commit comments