fix: limit load provider concurrent size

This commit is contained in:
Skyxim 2022-05-08 22:52:46 +08:00
parent 2072964701
commit 463101aec1
4 changed files with 26 additions and 3 deletions

View file

@ -0,0 +1,5 @@
//go:build !386 && !amd64 && !arm64 && !arm64be && !mipsle && !mips
package executor
const concurrentCount = 5

View file

@ -0,0 +1,5 @@
//go:build mips || mipsle
package executor
const concurrentCount = 1

View file

@ -0,0 +1,7 @@
//go:build 386 || amd64 || arm64 || arm64be
package executor
import "math"
const concurrentCount = math.MaxInt

View file

@ -78,8 +78,8 @@ func ApplyConfig(cfg *config.Config, force bool) {
updateRules(cfg.Rules, cfg.RuleProviders)
updateSniffer(cfg.Sniffer)
updateHosts(cfg.Hosts)
updateDNS(cfg.DNS)
initInnerTcp()
updateDNS(cfg.DNS)
loadProxyProvider(cfg.Providers)
updateProfile(cfg)
loadRuleProvider(cfg.RuleProviders)
@ -211,12 +211,15 @@ func loadProvider(pv provider.Provider) {
func loadRuleProvider(ruleProviders map[string]provider.RuleProvider) {
wg := sync.WaitGroup{}
ch := make(chan struct{}, concurrentCount)
for _, ruleProvider := range ruleProviders {
ruleProvider := ruleProvider
wg.Add(1)
ch <- struct{}{}
go func() {
defer func() { wg.Done() }()
defer func() { <-ch; wg.Done() }()
loadProvider(ruleProvider)
}()
}
@ -224,12 +227,15 @@ func loadRuleProvider(ruleProviders map[string]provider.RuleProvider) {
}
func loadProxyProvider(proxyProviders map[string]provider.ProxyProvider) {
// limit concurrent size
wg := sync.WaitGroup{}
ch := make(chan struct{}, concurrentCount)
for _, proxyProvider := range proxyProviders {
proxyProvider := proxyProvider
wg.Add(1)
ch <- struct{}{}
go func() {
defer func() { wg.Done() }()
defer func() { <-ch; wg.Done() }()
loadProvider(proxyProvider)
}()
}