Skip to content

Commit

Permalink
add 100 worker limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ying-zhu committed Oct 6, 2022
1 parent 2983bc4 commit 72909ab
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions pilot/pkg/model/push_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 72909ab

Please sign in to comment.