Skip to content

Commit 275da7a

Browse files
Benchmark for topology spreading filter
Signed-off-by: Aldo Culquicondor <[email protected]>
1 parent fce286e commit 275da7a

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pkg/scheduler/framework/plugins/podtopologyspread/filtering_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/client-go/kubernetes/fake"
3131
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
3232
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
33+
"k8s.io/kubernetes/pkg/scheduler/internal/parallelize"
3334
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
3435
st "k8s.io/kubernetes/pkg/scheduler/testing"
3536
)
@@ -1065,7 +1066,7 @@ func TestPreFilterStateRemovePod(t *testing.T) {
10651066
}
10661067
}
10671068

1068-
func BenchmarkTestCalPreFilterState(b *testing.B) {
1069+
func BenchmarkFilter(b *testing.B) {
10691070
tests := []struct {
10701071
name string
10711072
pod *v1.Pod
@@ -1103,17 +1104,30 @@ func BenchmarkTestCalPreFilterState(b *testing.B) {
11031104
},
11041105
}
11051106
for _, tt := range tests {
1107+
var state *framework.CycleState
11061108
b.Run(tt.name, func(b *testing.B) {
11071109
existingPods, allNodes, _ := st.MakeNodesAndPodsForEvenPodsSpread(tt.pod.Labels, tt.existingPodsNum, tt.allNodesNum, tt.filteredNodesNum)
11081110
pl := PodTopologySpread{
11091111
sharedLister: cache.NewSnapshot(existingPods, allNodes),
11101112
}
1113+
ctx := context.Background()
11111114
b.ResetTimer()
11121115
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)
11141118
if !s.IsSuccess() {
11151119
b.Fatal(s.AsError())
11161120
}
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()
11171131
}
11181132
})
11191133
}

0 commit comments

Comments
 (0)