@@ -30,6 +30,7 @@ import (
30
30
"k8s.io/client-go/kubernetes/fake"
31
31
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
32
32
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
33
+ "k8s.io/kubernetes/pkg/scheduler/internal/parallelize"
33
34
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
34
35
st "k8s.io/kubernetes/pkg/scheduler/testing"
35
36
)
@@ -1065,7 +1066,7 @@ func TestPreFilterStateRemovePod(t *testing.T) {
1065
1066
}
1066
1067
}
1067
1068
1068
- func BenchmarkTestCalPreFilterState (b * testing.B ) {
1069
+ func BenchmarkFilter (b * testing.B ) {
1069
1070
tests := []struct {
1070
1071
name string
1071
1072
pod * v1.Pod
@@ -1103,17 +1104,30 @@ func BenchmarkTestCalPreFilterState(b *testing.B) {
1103
1104
},
1104
1105
}
1105
1106
for _ , tt := range tests {
1107
+ var state * framework.CycleState
1106
1108
b .Run (tt .name , func (b * testing.B ) {
1107
1109
existingPods , allNodes , _ := st .MakeNodesAndPodsForEvenPodsSpread (tt .pod .Labels , tt .existingPodsNum , tt .allNodesNum , tt .filteredNodesNum )
1108
1110
pl := PodTopologySpread {
1109
1111
sharedLister : cache .NewSnapshot (existingPods , allNodes ),
1110
1112
}
1113
+ ctx := context .Background ()
1111
1114
b .ResetTimer ()
1112
1115
for i := 0 ; i < b .N ; i ++ {
1113
- s := pl .PreFilter (context .Background (), framework .NewCycleState (), tt .pod )
1116
+ state = framework .NewCycleState ()
1117
+ s := pl .PreFilter (ctx , state , tt .pod )
1114
1118
if ! s .IsSuccess () {
1115
1119
b .Fatal (s .AsError ())
1116
1120
}
1121
+ filterNode := func (i int ) {
1122
+ n , _ := pl .sharedLister .NodeInfos ().Get (allNodes [i ].Name )
1123
+ pl .Filter (ctx , state , tt .pod , n )
1124
+ }
1125
+ parallelize .Until (ctx , len (allNodes ), filterNode )
1126
+ }
1127
+ })
1128
+ b .Run (tt .name + "/Clone" , func (b * testing.B ) {
1129
+ for i := 0 ; i < b .N ; i ++ {
1130
+ state .Clone ()
1117
1131
}
1118
1132
})
1119
1133
}
0 commit comments