Skip to content

Commit 3a84906

Browse files
authored
Merge pull request kubernetes#125884 from serathius/benchmark-storage
Benchmark storage
2 parents 619b005 + fa50088 commit 3a84906

File tree

7 files changed

+323
-5
lines changed

7 files changed

+323
-5
lines changed

go.work.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 h1:G1bPvciwNyF7IU
379379
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I=
380380
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to=
381381
github.com/aws/aws-sdk-go v1.35.24 h1:U3GNTg8+7xSM6OAJ8zksiSM4bRqxBWmVwwehvOSNG3A=
382+
github.com/aws/aws-sdk-go v1.35.24/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
382383
github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY=
383384
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c h1:+0HFd5KSZ/mm3JmhmrDukiId5iR6w4+BdFtfSy4yWIc=
384385
github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g=
@@ -432,6 +433,7 @@ github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG
432433
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
433434
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
434435
github.com/gogo/googleapis v1.4.1 h1:1Yx4Myt7BxzvUr5ldGSbwYiZG6t9wGBZ+8/fX3Wvtq0=
436+
github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4=
435437
github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68=
436438
github.com/golang/glog v1.2.1 h1:OptwRhECazUx5ix5TTWC3EZhsZEHWcYWY4FQHTIubm4=
437439
github.com/golang/mock v1.1.1 h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8=
@@ -491,6 +493,7 @@ github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47
491493
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639 h1:mV02weKRL81bEnm8A0HT1/CAelMQDBuQIfLw8n+d6xI=
492494
github.com/ianlancetaylor/demangle v0.0.0-20240312041847-bd984b5ce465 h1:KwWnWVWCNtNq/ewIX7HIKnELmEx2nDP42yskD/pi7QE=
493495
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
496+
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
494497
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
495498
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024 h1:rBMNdlhTLzJjJSDIjNEXX1Pz3Hmwmz91v+zycvx9PJc=
496499
github.com/jstemmer/go-junit-report v0.9.1 h1:6QPYqodiu3GuPL+7mfx+NwDdp2eTkp9IfEUpgAwUN0o=
@@ -515,6 +518,7 @@ github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzR
515518
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
516519
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
517520
github.com/matttproud/golang_protobuf_extensions v1.0.2 h1:hAHbPm5IJGijwng3PWk09JkG9WeqChjprR5s9bBZ+OM=
521+
github.com/matttproud/golang_protobuf_extensions v1.0.2/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
518522
github.com/miekg/dns v1.0.14 h1:9jZdLNd/P4+SfEJ0TNyxYpsK8N4GtfylBLqtbYN1sbA=
519523
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY=
520524
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
@@ -525,6 +529,7 @@ github.com/mitchellh/gox v0.4.0 h1:lfGJxY7ToLJQjHHwi0EX6uYBdK78egf954SQl13PQJc=
525529
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
526530
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
527531
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
532+
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
528533
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
529534
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
530535
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=

staging/src/k8s.io/apiserver/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/coreos/go-systemd/v22 v22.5.0
1111
github.com/emicklei/go-restful/v3 v3.11.0
1212
github.com/fsnotify/fsnotify v1.7.0
13+
github.com/go-logr/logr v1.4.2
1314
github.com/gogo/protobuf v1.3.2
1415
github.com/google/cel-go v0.20.1
1516
github.com/google/gnostic-models v0.6.8
@@ -70,7 +71,6 @@ require (
7071
github.com/dustin/go-humanize v1.0.1 // indirect
7172
github.com/felixge/httpsnoop v1.0.4 // indirect
7273
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
73-
github.com/go-logr/logr v1.4.2 // indirect
7474
github.com/go-logr/stdr v1.2.2 // indirect
7575
github.com/go-openapi/jsonpointer v0.19.6 // indirect
7676
github.com/go-openapi/jsonreference v0.20.2 // indirect

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"testing"
2323
"time"
2424

25+
"github.com/go-logr/logr"
26+
2527
apiequality "k8s.io/apimachinery/pkg/api/equality"
2628
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2729
"k8s.io/apimachinery/pkg/fields"
@@ -37,7 +39,9 @@ import (
3739
etcd3testing "k8s.io/apiserver/pkg/storage/etcd3/testing"
3840
storagetesting "k8s.io/apiserver/pkg/storage/testing"
3941
utilfeature "k8s.io/apiserver/pkg/util/feature"
42+
"k8s.io/client-go/tools/cache"
4043
featuregatetesting "k8s.io/component-base/featuregate/testing"
44+
"k8s.io/klog/v2"
4145
"k8s.io/utils/clock"
4246
)
4347

@@ -396,6 +400,7 @@ type setupOptions struct {
396400
resourcePrefix string
397401
keyFunc func(runtime.Object) (string, error)
398402
indexerFuncs map[string]storage.IndexerFunc
403+
indexers cache.Indexers
399404
clock clock.WithTicker
400405
}
401406

@@ -425,14 +430,20 @@ func withSpecNodeNameIndexerFuncs(options *setupOptions) {
425430
return pod.Spec.NodeName
426431
},
427432
}
433+
options.indexers = map[string]cache.IndexFunc{
434+
"f:spec.nodeName": func(obj interface{}) ([]string, error) {
435+
pod := obj.(*example.Pod)
436+
return []string{pod.Spec.NodeName}, nil
437+
},
438+
}
428439
}
429440

430441
func testSetup(t *testing.T, opts ...setupOption) (context.Context, *Cacher, tearDownFunc) {
431442
ctx, cacher, _, tearDown := testSetupWithEtcdServer(t, opts...)
432443
return ctx, cacher, tearDown
433444
}
434445

435-
func testSetupWithEtcdServer(t *testing.T, opts ...setupOption) (context.Context, *Cacher, *etcd3testing.EtcdTestServer, tearDownFunc) {
446+
func testSetupWithEtcdServer(t testing.TB, opts ...setupOption) (context.Context, *Cacher, *etcd3testing.EtcdTestServer, tearDownFunc) {
436447
setupOpts := setupOptions{}
437448
opts = append([]setupOption{withDefaults}, opts...)
438449
for _, opt := range opts {
@@ -456,6 +467,7 @@ func testSetupWithEtcdServer(t *testing.T, opts ...setupOption) (context.Context
456467
NewFunc: newPod,
457468
NewListFunc: newPodList,
458469
IndexerFuncs: setupOpts.indexerFuncs,
470+
Indexers: &setupOpts.indexers,
459471
Codec: codecs.LegacyCodec(examplev1.SchemeGroupVersion),
460472
Clock: setupOpts.clock,
461473
}
@@ -521,3 +533,24 @@ func (c *createWrapper) Create(ctx context.Context, key string, obj, out runtime
521533
return true, nil
522534
})
523535
}
536+
537+
func BenchmarkStoreListCreate(b *testing.B) {
538+
klog.SetLogger(logr.Discard())
539+
b.Run("RV=NotOlderThan", func(b *testing.B) {
540+
ctx, cacher, _, terminate := testSetupWithEtcdServer(b)
541+
b.Cleanup(terminate)
542+
storagetesting.RunBenchmarkStoreListCreate(ctx, b, cacher, metav1.ResourceVersionMatchNotOlderThan)
543+
})
544+
b.Run("RV=ExactMatch", func(b *testing.B) {
545+
ctx, cacher, _, terminate := testSetupWithEtcdServer(b)
546+
b.Cleanup(terminate)
547+
storagetesting.RunBenchmarkStoreListCreate(ctx, b, cacher, metav1.ResourceVersionMatchExact)
548+
})
549+
}
550+
551+
func BenchmarkStoreList(b *testing.B) {
552+
klog.SetLogger(logr.Discard())
553+
ctx, cacher, _, terminate := testSetupWithEtcdServer(b, withSpecNodeNameIndexerFuncs)
554+
b.Cleanup(terminate)
555+
storagetesting.RunBenchmarkStoreList(ctx, b, cacher)
556+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func init() {
5555
func newPod() runtime.Object { return &example.Pod{} }
5656
func newPodList() runtime.Object { return &example.PodList{} }
5757

58-
func newEtcdTestStorage(t *testing.T, prefix string) (*etcd3testing.EtcdTestServer, storage.Interface) {
58+
func newEtcdTestStorage(t testing.TB, prefix string) (*etcd3testing.EtcdTestServer, storage.Interface) {
5959
server, _ := etcd3testing.NewUnsecuredEtcd3TestClientServer(t)
6060
storage := etcd3.New(
6161
server.V3Client,

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"sync/atomic"
2828
"testing"
2929

30+
"github.com/go-logr/logr"
3031
clientv3 "go.etcd.io/etcd/client/v3"
3132
"go.etcd.io/etcd/server/v3/embed"
3233
"google.golang.org/grpc/grpclog"
@@ -45,6 +46,7 @@ import (
4546
"k8s.io/apiserver/pkg/storage/etcd3/testserver"
4647
storagetesting "k8s.io/apiserver/pkg/storage/testing"
4748
"k8s.io/apiserver/pkg/storage/value"
49+
"k8s.io/klog/v2"
4850
)
4951

5052
var scheme = runtime.NewScheme()
@@ -905,3 +907,20 @@ func BenchmarkStore_GetList(b *testing.B) {
905907
})
906908
}
907909
}
910+
911+
func BenchmarkStoreListCreate(b *testing.B) {
912+
klog.SetLogger(logr.Discard())
913+
b.Run("RV=NotOlderThan", func(b *testing.B) {
914+
ctx, store, _ := testSetup(b)
915+
storagetesting.RunBenchmarkStoreListCreate(ctx, b, store, metav1.ResourceVersionMatchNotOlderThan)
916+
})
917+
b.Run("RV=ExactMatch", func(b *testing.B) {
918+
ctx, store, _ := testSetup(b)
919+
storagetesting.RunBenchmarkStoreListCreate(ctx, b, store, metav1.ResourceVersionMatchExact)
920+
})
921+
}
922+
923+
func BenchmarkStoreList(b *testing.B) {
924+
ctx, store, _ := testSetup(b)
925+
storagetesting.RunBenchmarkStoreList(ctx, b, store)
926+
}

staging/src/k8s.io/apiserver/pkg/storage/etcd3/testing/test_server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ type EtcdTestServer struct {
3030
V3Client *clientv3.Client
3131
}
3232

33-
func (e *EtcdTestServer) Terminate(t *testing.T) {
33+
func (e *EtcdTestServer) Terminate(t testing.TB) {
3434
// no-op, server termination moved to test cleanup
3535
}
3636

3737
// NewUnsecuredEtcd3TestClientServer creates a new client and server for testing
38-
func NewUnsecuredEtcd3TestClientServer(t *testing.T) (*EtcdTestServer, *storagebackend.Config) {
38+
func NewUnsecuredEtcd3TestClientServer(t testing.TB) (*EtcdTestServer, *storagebackend.Config) {
3939
server := &EtcdTestServer{}
4040
server.V3Client = testserver.RunEtcd(t, nil)
4141
config := &storagebackend.Config{

0 commit comments

Comments
 (0)