-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
✨client: client.MatchingFields support multiple indexes #2512
Conversation
Hi @halfcrazy. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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. |
/hold After reading #1838 (review) seems we need an atomic operation here. |
452eedb
to
9727ea2
Compare
/unhold |
/ok-to-test |
/retest |
8622a7e
to
f9176e0
Compare
add support for multiple indexes when using client.MatchingFields
f9176e0
to
c943a3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, halfcrazy The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
hi @halfcrazy can you give a short explanation about the expected performance of this implementation? how does it grow in relation to: 1- number of objects in store, 2- number of selectors. my local tests show somewhat linear growth by both.. |
In my local environment, there is an obvious step between 1 and 2 indexes and linear growth for more indexes. In the long term, if upstream supports ByIndexes there would be a performance improve to eliminate the gap between 1 and more indexes.
package internal
import (
"fmt"
"strconv"
"strings"
"testing"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/client-go/tools/cache"
)
func benchmarkByIndexes(sel fields.Selector, b *testing.B) {
requires := sel.Requirements()
indexFunc := func(val string) func(obj interface{}) ([]string, error) {
return func(obj interface{}) ([]string, error) {
pod := obj.(*corev1.Pod)
if strings.Contains(pod.Labels["foo"], val) {
return []string{KeyToNamespacedKey("", val)}, nil
}
return nil, nil
}
}
index := cache.NewIndexer(cache.MetaNamespaceKeyFunc, cache.Indexers{
FieldIndexName("idx1"): indexFunc("1"),
FieldIndexName("idx2"): indexFunc("2"),
FieldIndexName("idx3"): indexFunc("3"),
FieldIndexName("idx4"): indexFunc("4"),
FieldIndexName("idx5"): indexFunc("5"),
})
for i := 0; i < 15000; i++ {
err := index.Add(&corev1.Pod{ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("test-pod-%d", i), Labels: map[string]string{"foo": strconv.Itoa(i)}}})
if err != nil {
b.Fatal(err)
}
}
for i := 0; i < b.N; i++ {
objs, err := byIndexes(index, requires, "")
if err != nil {
b.Fatal(err)
}
if len(objs) == 0 {
b.Fatal("expect to match objs, got 0")
}
}
}
func BenchmarkByIndexes1(b *testing.B) {
sel := fields.ParseSelectorOrDie("idx1=1")
benchmarkByIndexes(sel, b)
}
func BenchmarkByIndexes2(b *testing.B) {
sel := fields.ParseSelectorOrDie("idx1=1,idx2=2")
benchmarkByIndexes(sel, b)
}
func BenchmarkByIndexes3(b *testing.B) {
sel := fields.ParseSelectorOrDie("idx1=1,idx2=2,idx3=3")
benchmarkByIndexes(sel, b)
}
func BenchmarkByIndexes4(b *testing.B) {
sel := fields.ParseSelectorOrDie("idx1=1,idx2=2,idx3=3,idx4=4")
benchmarkByIndexes(sel, b)
}
func BenchmarkByIndexes5(b *testing.B) {
sel := fields.ParseSelectorOrDie("idx1=1,idx2=2,idx3=3,idx4=4,idx5=5")
benchmarkByIndexes(sel, b)
} |
@halfcrazy interesting so this indexing, and maybe k8s client-go indexes in general, does not really provide map-like lookup performance. it is a more of a convenience method. |
add support for multiple indexes when using client.MatchingFields
Fix #612