mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-17 23:57:52 +00:00
Improve fake clientset performance
The fake clientset used a slice to store each kind of objects, it's quite slow to init the clientset with massive objects because it checked existence of an object by traversing all objects before adding it, which leads to O(n^2) time complexity. Also, the Create, Update, Get, Delete methods needs to traverse all objects, which affects the time statistic of code that calls them. This patch changed to use a map to store each kind of objects, reduced the time complexity of initializing clientset to O(n) and the Create, Update, Get, Delete to O(1). For example: Before this patch, it took ~29s to init a clientset with 30000 Pods, and 2~4ms to create and get an Pod. After this patch, it took ~50ms to init a clientset with 30000 Pods, and tens of µs to create and get an Pod. Kubernetes-commit: 7e15e31e11e48a6db855e30ca9b07dbce3047577
This commit is contained in:
committed by
Kubernetes Publisher
parent
6240434e1a
commit
faf5681d1c
@@ -75,9 +75,9 @@ func TestList(t *testing.T) {
|
||||
}
|
||||
|
||||
expected := []unstructured.Unstructured{
|
||||
*newUnstructured("group/version", "TheKind", "ns-foo", "name-foo"),
|
||||
*newUnstructured("group/version", "TheKind", "ns-foo", "name-bar"),
|
||||
*newUnstructured("group/version", "TheKind", "ns-foo", "name-baz"),
|
||||
*newUnstructured("group/version", "TheKind", "ns-foo", "name-foo"),
|
||||
}
|
||||
if !equality.Semantic.DeepEqual(listFirst.Items, expected) {
|
||||
t.Fatal(diff.ObjectGoPrintDiff(expected, listFirst.Items))
|
||||
|
Reference in New Issue
Block a user