From 72909ab92905282b53113ede6298d49b562d0055 Mon Sep 17 00:00:00 2001 From: ying-zhu Date: Wed, 5 Oct 2022 18:54:51 -0700 Subject: [PATCH] add 100 worker limit --- pilot/pkg/model/push_context.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/pilot/pkg/model/push_context.go b/pilot/pkg/model/push_context.go index da2e0e39489c..cc755e63e7df 100644 --- a/pilot/pkg/model/push_context.go +++ b/pilot/pkg/model/push_context.go @@ -1664,14 +1664,31 @@ func (ps *PushContext) initSidecarScopes(env *Environment) error { } ps.sidecarIndex.rootConfig = rootNSConfig + numWorkers := 100 + configsPerWorker := len(sidecarConfigs) / 100 + if configsPerWorker == 0 { + configsPerWorker = 1 + } + ch := make(chan *SidecarScope) + var wg sync.WaitGroup - wg.Add(len(sidecarConfigs)) - for _, sidecarConfig := range sidecarConfigs { - go func(c config.Config) { + wg.Add(numWorkers) + for i := 0; i < numWorkers; i++ { + go func(i int) { defer wg.Done() - ch <- ConvertToSidecarScope(ps, &sidecarConfig, sidecarConfig.Namespace) - }(sidecarConfig) + // [start,end) + start := i * configsPerWorker + end := (i + 1) * configsPerWorker + if len(sidecarConfigs) < end { + end = len(sidecarConfigs) + } + + for j := start; j < end; j++ { + c := sidecarConfigs[j] + ch <- ConvertToSidecarScope(ps, &c, c.Namespace) + } + }(i) } go func() {