Skip to content

Commit d2b1903

Browse files
Calculate scores in parallel on spreading benchmarks
This is closer to what happens in the core scheduler Signed-off-by: Aldo Culquicondor <[email protected]>
1 parent 4b31b55 commit d2b1903

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

pkg/scheduler/framework/plugins/defaultpodtopologyspread/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ go_test(
2727
deps = [
2828
"//pkg/scheduler/framework/v1alpha1:go_default_library",
2929
"//pkg/scheduler/internal/cache:go_default_library",
30+
"//pkg/scheduler/internal/parallelize:go_default_library",
3031
"//pkg/scheduler/testing:go_default_library",
3132
"//staging/src/k8s.io/api/apps/v1:go_default_library",
3233
"//staging/src/k8s.io/api/core/v1:go_default_library",

pkg/scheduler/framework/plugins/defaultpodtopologyspread/default_pod_topology_spread_perf_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/client-go/kubernetes/fake"
2626
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
2727
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
28+
"k8s.io/kubernetes/pkg/scheduler/internal/parallelize"
2829
st "k8s.io/kubernetes/pkg/scheduler/testing"
2930
)
3031

@@ -76,15 +77,14 @@ func BenchmarkTestSelectorSpreadPriority(b *testing.B) {
7677
if !status.IsSuccess() {
7778
b.Fatalf("unexpected error: %v", status)
7879
}
79-
var gotList framework.NodeScoreList
80-
for _, node := range filteredNodes {
81-
score, status := plugin.Score(ctx, state, pod, node.Name)
82-
if !status.IsSuccess() {
83-
b.Errorf("unexpected error: %v", status)
84-
}
85-
gotList = append(gotList, framework.NodeScore{Name: node.Name, Score: score})
80+
gotList := make(framework.NodeScoreList, len(filteredNodes))
81+
scoreNode := func(i int) {
82+
n := filteredNodes[i]
83+
score, _ := plugin.Score(ctx, state, pod, n.Name)
84+
gotList[i] = framework.NodeScore{Name: n.Name, Score: score}
8685
}
87-
status = plugin.NormalizeScore(context.Background(), state, pod, gotList)
86+
parallelize.Until(ctx, len(filteredNodes), scoreNode)
87+
status = plugin.NormalizeScore(ctx, state, pod, gotList)
8888
if !status.IsSuccess() {
8989
b.Fatal(status)
9090
}

pkg/scheduler/framework/plugins/podtopologyspread/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ go_test(
4141
deps = [
4242
"//pkg/scheduler/framework/v1alpha1:go_default_library",
4343
"//pkg/scheduler/internal/cache:go_default_library",
44+
"//pkg/scheduler/internal/parallelize:go_default_library",
4445
"//pkg/scheduler/nodeinfo:go_default_library",
4546
"//pkg/scheduler/testing:go_default_library",
4647
"//staging/src/k8s.io/api/apps/v1:go_default_library",

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"k8s.io/client-go/kubernetes/fake"
3030
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
3131
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
32+
"k8s.io/kubernetes/pkg/scheduler/internal/parallelize"
3233
st "k8s.io/kubernetes/pkg/scheduler/testing"
3334
"k8s.io/utils/pointer"
3435
)
@@ -746,19 +747,18 @@ func BenchmarkTestDefaultEvenPodsSpreadPriority(b *testing.B) {
746747
b.ResetTimer()
747748

748749
for i := 0; i < b.N; i++ {
749-
var gotList framework.NodeScoreList
750750
status := p.PreScore(ctx, state, pod, filteredNodes)
751751
if !status.IsSuccess() {
752752
b.Fatalf("unexpected error: %v", status)
753753
}
754-
for _, n := range filteredNodes {
755-
score, status := p.Score(context.Background(), state, pod, n.Name)
756-
if !status.IsSuccess() {
757-
b.Fatalf("unexpected error: %v", status)
758-
}
759-
gotList = append(gotList, framework.NodeScore{Name: n.Name, Score: score})
754+
gotList := make(framework.NodeScoreList, len(filteredNodes))
755+
scoreNode := func(i int) {
756+
n := filteredNodes[i]
757+
score, _ := p.Score(ctx, state, pod, n.Name)
758+
gotList[i] = framework.NodeScore{Name: n.Name, Score: score}
760759
}
761-
status = p.NormalizeScore(context.Background(), state, pod, gotList)
760+
parallelize.Until(ctx, len(filteredNodes), scoreNode)
761+
status = p.NormalizeScore(ctx, state, pod, gotList)
762762
if !status.IsSuccess() {
763763
b.Fatal(status)
764764
}

0 commit comments

Comments
 (0)