Merge pull request #102330 from tnqn/replicaset-optimization

Add controllerUID index to improve ReplicaSetController performance
This commit is contained in:
Kubernetes Prow Robot
2022-02-10 10:15:46 -08:00
committed by GitHub
2 changed files with 54 additions and 7 deletions

View File

@@ -36,6 +36,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/apimachinery/pkg/util/wait"
@@ -438,6 +439,36 @@ func TestGetReplicaSetsWithSameController(t *testing.T) {
}
}
func BenchmarkGetReplicaSetsWithSameController(b *testing.B) {
stopCh := make(chan struct{})
defer close(stopCh)
controller, informers := testNewReplicaSetControllerFromClient(clientset.NewForConfigOrDie(&restclient.Config{Host: "", ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}}), stopCh, BurstReplicas)
targetRS := newReplicaSet(1, map[string]string{"foo": "bar"})
targetRS.Name = "rs1"
targetRS.ObjectMeta.OwnerReferences[0].UID = "123456"
informers.Apps().V1().ReplicaSets().Informer().GetIndexer().Add(targetRS)
relatedRS := newReplicaSet(1, map[string]string{"foo": "bar"})
relatedRS.Name = "rs2"
relatedRS.ObjectMeta.OwnerReferences[0].UID = "123456"
informers.Apps().V1().ReplicaSets().Informer().GetIndexer().Add(relatedRS)
for i := 0; i < 100; i++ {
unrelatedRS := newReplicaSet(1, map[string]string{"foo": fmt.Sprintf("baz-%d", i)})
unrelatedRS.Name = fmt.Sprintf("rs-%d", i)
unrelatedRS.ObjectMeta.OwnerReferences[0].UID = types.UID(fmt.Sprintf("%d", i))
informers.Apps().V1().ReplicaSets().Informer().GetIndexer().Add(unrelatedRS)
}
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
gotRSs := controller.getReplicaSetsWithSameController(targetRS)
if len(gotRSs) != 2 {
b.Errorf("Incorrect ReplicaSets number, expected 2, got: %d", len(gotRSs))
}
}
}
func TestPodControllerLookup(t *testing.T) {
stopCh := make(chan struct{})
defer close(stopCh)