Skip to content

Commit b56d38e

Browse files
authored
Merge pull request kubernetes#129441 from serathius/watchcache-benchmark
Improve benchmark to handle multiple dimensions
2 parents 10fb206 + 4a0578e commit b56d38e

File tree

3 files changed

+204
-131
lines changed

3 files changed

+204
-131
lines changed

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_test.go

Lines changed: 93 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -547,23 +547,102 @@ func (c *createWrapper) Create(ctx context.Context, key string, obj, out runtime
547547
})
548548
}
549549

550-
func BenchmarkStoreListCreate(b *testing.B) {
550+
func BenchmarkStoreCreateList(b *testing.B) {
551551
klog.SetLogger(logr.Discard())
552-
b.Run("RV=NotOlderThan", func(b *testing.B) {
553-
ctx, cacher, _, terminate := testSetupWithEtcdServer(b)
554-
b.Cleanup(terminate)
555-
storagetesting.RunBenchmarkStoreListCreate(ctx, b, cacher, metav1.ResourceVersionMatchNotOlderThan)
556-
})
557-
b.Run("RV=ExactMatch", func(b *testing.B) {
558-
ctx, cacher, _, terminate := testSetupWithEtcdServer(b)
559-
b.Cleanup(terminate)
560-
storagetesting.RunBenchmarkStoreListCreate(ctx, b, cacher, metav1.ResourceVersionMatchExact)
561-
})
552+
storeOptions := []struct {
553+
name string
554+
btreeEnabled bool
555+
}{
556+
{
557+
name: "Btree",
558+
btreeEnabled: true,
559+
},
560+
{
561+
name: "Map",
562+
btreeEnabled: false,
563+
},
564+
}
565+
for _, store := range storeOptions {
566+
b.Run(fmt.Sprintf("Store=%s", store.name), func(b *testing.B) {
567+
featuregatetesting.SetFeatureGateDuringTest(b, utilfeature.DefaultFeatureGate, features.BtreeWatchCache, store.btreeEnabled)
568+
for _, rvm := range []metav1.ResourceVersionMatch{metav1.ResourceVersionMatchNotOlderThan, metav1.ResourceVersionMatchExact} {
569+
b.Run(fmt.Sprintf("RV=%s", rvm), func(b *testing.B) {
570+
for _, useIndex := range []bool{true, false} {
571+
b.Run(fmt.Sprintf("Indexed=%v", useIndex), func(b *testing.B) {
572+
opts := []setupOption{}
573+
if useIndex {
574+
opts = append(opts, withSpecNodeNameIndexerFuncs)
575+
}
576+
ctx, cacher, _, terminate := testSetupWithEtcdServer(b, opts...)
577+
b.Cleanup(terminate)
578+
storagetesting.RunBenchmarkStoreListCreate(ctx, b, cacher, rvm)
579+
})
580+
}
581+
})
582+
}
583+
})
584+
}
562585
}
563586

564587
func BenchmarkStoreList(b *testing.B) {
565588
klog.SetLogger(logr.Discard())
566-
ctx, cacher, _, terminate := testSetupWithEtcdServer(b, withSpecNodeNameIndexerFuncs)
567-
b.Cleanup(terminate)
568-
storagetesting.RunBenchmarkStoreList(ctx, b, cacher)
589+
// Based on https://github.com/kubernetes/community/blob/master/sig-scalability/configs-and-limits/thresholds.md
590+
dimensions := []struct {
591+
namespaceCount int
592+
podPerNamespaceCount int
593+
nodeCount int
594+
}{
595+
{
596+
namespaceCount: 10_000,
597+
podPerNamespaceCount: 15,
598+
nodeCount: 5_000,
599+
},
600+
{
601+
namespaceCount: 50,
602+
podPerNamespaceCount: 3_000,
603+
nodeCount: 5_000,
604+
},
605+
{
606+
namespaceCount: 100,
607+
podPerNamespaceCount: 1_100,
608+
nodeCount: 1000,
609+
},
610+
}
611+
for _, dims := range dimensions {
612+
b.Run(fmt.Sprintf("Namespaces=%d/Pods=%d/Nodes=%d", dims.namespaceCount, dims.namespaceCount*dims.podPerNamespaceCount, dims.nodeCount), func(b *testing.B) {
613+
data := storagetesting.PrepareBenchchmarkData(dims.namespaceCount, dims.podPerNamespaceCount, dims.nodeCount)
614+
storeOptions := []struct {
615+
name string
616+
btreeEnabled bool
617+
}{
618+
{
619+
name: "Btree",
620+
btreeEnabled: true,
621+
},
622+
{
623+
name: "Map",
624+
btreeEnabled: false,
625+
},
626+
}
627+
for _, store := range storeOptions {
628+
b.Run(fmt.Sprintf("Store=%s", store.name), func(b *testing.B) {
629+
featuregatetesting.SetFeatureGateDuringTest(b, utilfeature.DefaultFeatureGate, features.BtreeWatchCache, store.btreeEnabled)
630+
ctx, cacher, _, terminate := testSetupWithEtcdServer(b, withSpecNodeNameIndexerFuncs)
631+
b.Cleanup(terminate)
632+
var out example.Pod
633+
for _, pod := range data.Pods {
634+
err := cacher.Create(ctx, computePodKey(pod), pod, &out, 0)
635+
if err != nil {
636+
b.Fatal(err)
637+
}
638+
}
639+
for _, useIndex := range []bool{true, false} {
640+
b.Run(fmt.Sprintf("Indexed=%v", useIndex), func(b *testing.B) {
641+
storagetesting.RunBenchmarkStoreList(ctx, b, cacher, data, useIndex)
642+
})
643+
}
644+
})
645+
}
646+
})
647+
}
569648
}

staging/src/k8s.io/apiserver/pkg/storage/etcd3/store_test.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,45 @@ func BenchmarkStoreListCreate(b *testing.B) {
952952
}
953953

954954
func BenchmarkStoreList(b *testing.B) {
955-
ctx, store, _ := testSetup(b)
956-
storagetesting.RunBenchmarkStoreList(ctx, b, store)
955+
klog.SetLogger(logr.Discard())
956+
// Based on https://github.com/kubernetes/community/blob/master/sig-scalability/configs-and-limits/thresholds.md
957+
dimensions := []struct {
958+
namespaceCount int
959+
podPerNamespaceCount int
960+
nodeCount int
961+
}{
962+
{
963+
namespaceCount: 10_000,
964+
podPerNamespaceCount: 15,
965+
nodeCount: 5_000,
966+
},
967+
{
968+
namespaceCount: 50,
969+
podPerNamespaceCount: 3_000,
970+
nodeCount: 5_000,
971+
},
972+
{
973+
namespaceCount: 100,
974+
podPerNamespaceCount: 1_100,
975+
nodeCount: 1000,
976+
},
977+
}
978+
for _, dims := range dimensions {
979+
b.Run(fmt.Sprintf("Namespaces=%d/Pods=%d/Nodes=%d", dims.namespaceCount, dims.namespaceCount*dims.podPerNamespaceCount, dims.nodeCount), func(b *testing.B) {
980+
data := storagetesting.PrepareBenchchmarkData(dims.namespaceCount, dims.podPerNamespaceCount, dims.nodeCount)
981+
ctx, store, _ := testSetup(b)
982+
var out example.Pod
983+
for _, pod := range data.Pods {
984+
err := store.Create(ctx, computePodKey(pod), pod, &out, 0)
985+
if err != nil {
986+
b.Fatal(err)
987+
}
988+
}
989+
storagetesting.RunBenchmarkStoreList(ctx, b, store, data, false)
990+
})
991+
}
992+
}
993+
994+
func computePodKey(obj *example.Pod) string {
995+
return fmt.Sprintf("/pods/%s/%s", obj.Namespace, obj.Name)
957996
}

0 commit comments

Comments
 (0)