mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
Merge pull request #102330 from tnqn/replicaset-optimization
Add controllerUID index to improve ReplicaSetController performance
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user