From d4b694a49778e16a6013af80f34b9764e335936e Mon Sep 17 00:00:00 2001 From: Rob Scott Date: Tue, 17 Sep 2019 17:10:39 -0700 Subject: [PATCH] Updating EndpointSliceCache sort function to be significantly faster. The .IP() call that was previously used for sorting resulted in a call to netutil to parse an IP out of an IP:Port string. This was very slow and resulted in this sort taking up ~50% of total CPU util for kube-proxy. --- pkg/proxy/endpointslicecache.go | 2 +- pkg/proxy/endpointslicecache_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/proxy/endpointslicecache.go b/pkg/proxy/endpointslicecache.go index faef69daed8..141e854cfb9 100644 --- a/pkg/proxy/endpointslicecache.go +++ b/pkg/proxy/endpointslicecache.go @@ -249,5 +249,5 @@ func (e byIP) Swap(i, j int) { e[i], e[j] = e[j], e[i] } func (e byIP) Less(i, j int) bool { - return e[i].IP() < e[j].IP() + return e[i].String() < e[j].String() } diff --git a/pkg/proxy/endpointslicecache_test.go b/pkg/proxy/endpointslicecache_test.go index d4d4af39529..6b41575a87b 100644 --- a/pkg/proxy/endpointslicecache_test.go +++ b/pkg/proxy/endpointslicecache_test.go @@ -99,8 +99,8 @@ func TestEndpointsMapFromESC(t *testing.T) { }, expectedMap: map[ServicePortName][]*BaseEndpointInfo{ makeServicePortName("ns1", "svc1", "port-0"): { - &BaseEndpointInfo{Endpoint: "10.0.1.1:80"}, &BaseEndpointInfo{Endpoint: "10.0.1.10:80"}, + &BaseEndpointInfo{Endpoint: "10.0.1.1:80"}, &BaseEndpointInfo{Endpoint: "10.0.1.2:80"}, &BaseEndpointInfo{Endpoint: "10.0.1.3:80"}, &BaseEndpointInfo{Endpoint: "10.0.1.4:80"},