mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-12-22 23:57:26 +08:00
fix: limit load provider concurrent size
This commit is contained in:
parent
2072964701
commit
463101aec1
5
hub/executor/concurrent_load_limit.go
Normal file
5
hub/executor/concurrent_load_limit.go
Normal file
@ -0,0 +1,5 @@
|
||||
//go:build !386 && !amd64 && !arm64 && !arm64be && !mipsle && !mips
|
||||
|
||||
package executor
|
||||
|
||||
const concurrentCount = 5
|
5
hub/executor/concurrent_load_single.go
Normal file
5
hub/executor/concurrent_load_single.go
Normal file
@ -0,0 +1,5 @@
|
||||
//go:build mips || mipsle
|
||||
|
||||
package executor
|
||||
|
||||
const concurrentCount = 1
|
7
hub/executor/concurrent_load_unlimit.go
Normal file
7
hub/executor/concurrent_load_unlimit.go
Normal file
@ -0,0 +1,7 @@
|
||||
//go:build 386 || amd64 || arm64 || arm64be
|
||||
|
||||
package executor
|
||||
|
||||
import "math"
|
||||
|
||||
const concurrentCount = math.MaxInt
|
@ -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)
|
||||
}()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user