-
Notifications
You must be signed in to change notification settings - Fork 38.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use GetByKey() in typeLister_NonNamespacedGet #54257
Conversation
The Get() function of non-namespace lister passes a temporary object to indexer.Get() in order to fetch the actual object from the indexer. This may cause Go to allocate the temporary object on the heap instead of the stack, as it is passed into interfaces. For non-namespaced objects, Get(&Type{ObjectMeta: v1.ObjectMeta{Name: name}}) should be equivalent to GetByKey(name). This could be the root cause of excessive allocations, e.g. in tests clusterRoleLister.Get() has trigger 4 billion allocations. See openshift/origin#16954 Signed-off-by: Christian Heimes <cheimes@redhat.com>
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Hi @tiran. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/ok-to-test |
Signed-off-by: Christian Heimes <cheimes@redhat.com>
/lgtm |
/lgtm |
@tiran: Adding do-not-merge/release-note-label-needed because the release note process has not been followed. One of the following labels is required "release-note", "release-note-action-required", or "release-note-none". Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Removed the release-note. This change is too internal to be seen in the changelogs. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: enj, sttts, tiran Assign the PR to them by writing Associated issue: 16954 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
First commit is approved. 2nd and 3rd are the tail of generated code only, approving. |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue (batch tested with PRs 53194, 54257, 53014). If you want to cherry-pick this change to another branch, please follow the instructions here. |
So I did a simple benchmark:
var dataD *rbac.ClusterRole
var errD error
func BenchmarkClusterRoleGetter(b *testing.B) {
idx := cache.NewIndexer(cache.DeletionHandlingMetaNamespaceKeyFunc, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
crl := bootstrappolicy.ClusterRoles()
for i := range crl {
if err := idx.Add(&crl[i]); err != nil {
b.Fatal(err)
}
}
var crg rbacregistryvalidation.ClusterRoleGetter = &ClusterRoleGetter{
Lister: rbaclisters.NewClusterRoleLister(idx),
}
var data *rbac.ClusterRole
var err error
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, cr := range crl {
data, err = crg.GetClusterRole(cr.Name)
if err != nil {
b.Fatal(err)
}
}
}
dataD = data
errD = err
} Allocations before this change:
CPU before this change:
Allocations after this change:
CPU after this change:
|
@wojtek-t This had a big impact on rbac authorization performance. |
Removing label |
Commit found in the "release-1.7" branch appears to be this PR. Removing the "cherrypick-candidate" label. If this is an error find help to get your PR picked. |
The Get() function of non-namespace lister passes a temporary object to
indexer.Get() in order to fetch the actual object from the indexer. This
may cause Go to allocate the temporary object on the heap instead of the
stack, as it is passed into interfaces. For non-namespaced objects,
Get(&Type{ObjectMeta: v1.ObjectMeta{Name: name}}) should be equivalent
to GetByKey(name).
This could be the root cause of excessive allocations, e.g. in tests
clusterRoleLister.Get() has trigger 4 billion allocations. See
openshift/origin#16954