From 4c8b190372aaf6eb6ccce07d1763d2d4e26eb98d Mon Sep 17 00:00:00 2001 From: Andrew Sy Kim Date: Thu, 29 Apr 2021 16:05:49 -0400 Subject: [PATCH] proxier/iptables: reuse the same variable for endpointchains for better memory consumption Signed-off-by: Andrew Sy Kim --- pkg/proxy/iptables/proxier.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index d745689d9e9..c8b49c1abe3 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -993,6 +993,11 @@ func (proxier *Proxier) syncProxyRules() { // slice = append(slice[:0], ...) endpoints := make([]*endpointsInfo, 0) endpointChains := make([]utiliptables.Chain, 0) + readyEndpoints := make([]*endpointsInfo, 0) + readyEndpointChains := make([]utiliptables.Chain, 0) + localReadyEndpointChains := make([]utiliptables.Chain, 0) + localServingTerminatingEndpointChains := make([]utiliptables.Chain, 0) + // To avoid growing this slice, we arbitrarily set its size to 64, // there is never more than that many arguments for a single line. // Note that even if we go over 64, it will still be correct - it @@ -1396,10 +1401,10 @@ func (proxier *Proxier) syncProxyRules() { // 1. all endpoints that are ready and NOT terminating. // 2. all endpoints that are local, ready and NOT terminating, and externalTrafficPolicy=Local // 3. all endpoints that are local, serving and terminating, and externalTrafficPolicy=Local - readyEndpointChains := make([]utiliptables.Chain, 0, len(endpointChains)) - readyEndpoints := make([]*endpointsInfo, 0, len(allEndpoints)) - localReadyEndpointChains := make([]utiliptables.Chain, 0, len(endpointChains)) - localServingTerminatingEndpointChains := make([]utiliptables.Chain, 0, len(endpointChains)) + readyEndpointChains = readyEndpointChains[:0] + readyEndpoints := readyEndpoints[:0] + localReadyEndpointChains := localReadyEndpointChains[:0] + localServingTerminatingEndpointChains := localServingTerminatingEndpointChains[:0] for i, endpointChain := range endpointChains { if endpoints[i].Ready { readyEndpointChains = append(readyEndpointChains, endpointChain)