Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 35 additions & 32 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,27 @@ import (
// General config
type General struct {
Inbound
Mode T.TunnelMode `json:"mode"`
UnifiedDelay bool `json:"unified-delay"`
LogLevel log.LogLevel `json:"log-level"`
IPv6 bool `json:"ipv6"`
Interface string `json:"interface-name"`
RoutingMark int `json:"routing-mark"`
GeoXUrl GeoXUrl `json:"geox-url"`
GeoAutoUpdate bool `json:"geo-auto-update"`
GeoUpdateInterval int `json:"geo-update-interval"`
GeodataMode bool `json:"geodata-mode"`
GeodataLoader string `json:"geodata-loader"`
GeositeMatcher string `json:"geosite-matcher"`
TCPConcurrent bool `json:"tcp-concurrent"`
FindProcessMode process.FindProcessMode `json:"find-process-mode"`
Sniffing bool `json:"sniffing"`
GlobalUA string `json:"global-ua"`
ETagSupport bool `json:"etag-support"`
KeepAliveIdle int `json:"keep-alive-idle"`
KeepAliveInterval int `json:"keep-alive-interval"`
DisableKeepAlive bool `json:"disable-keep-alive"`
Mode T.TunnelMode `json:"mode"`
UnifiedDelay bool `json:"unified-delay"`
LogLevel log.LogLevel `json:"log-level"`
IPv6 bool `json:"ipv6"`
Interface string `json:"interface-name"`
RoutingMark int `json:"routing-mark"`
GeoXUrl GeoXUrl `json:"geox-url"`
GeoAutoUpdate bool `json:"geo-auto-update"`
GeoUpdateInterval int `json:"geo-update-interval"`
GeodataMode bool `json:"geodata-mode"`
GeodataLoader string `json:"geodata-loader"`
GeositeMatcher string `json:"geosite-matcher"`
TCPConcurrent bool `json:"tcp-concurrent"`
ProviderLoadConcurrency int `json:"provider-load-concurrency"`
FindProcessMode process.FindProcessMode `json:"find-process-mode"`
Sniffing bool `json:"sniffing"`
GlobalUA string `json:"global-ua"`
ETagSupport bool `json:"etag-support"`
KeepAliveIdle int `json:"keep-alive-idle"`
KeepAliveInterval int `json:"keep-alive-interval"`
DisableKeepAlive bool `json:"disable-keep-alive"`
}

// Inbound config
Expand Down Expand Up @@ -436,6 +437,7 @@ type RawConfig struct {
GeodataLoader string `yaml:"geodata-loader" json:"geodata-loader"`
GeositeMatcher string `yaml:"geosite-matcher" json:"geosite-matcher"`
TCPConcurrent bool `yaml:"tcp-concurrent" json:"tcp-concurrent"`
ProviderLoadConcurrency int `yaml:"provider-load-concurrency" json:"provider-load-concurrency"`
FindProcessMode process.FindProcessMode `yaml:"find-process-mode" json:"find-process-mode"`
GlobalClientFingerprint string `yaml:"global-client-fingerprint" json:"global-client-fingerprint"`
GlobalUA string `yaml:"global-ua" json:"global-ua"`
Expand Down Expand Up @@ -785,18 +787,19 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
ASN: cfg.GeoXUrl.ASN,
GeoSite: cfg.GeoXUrl.GeoSite,
},
GeoAutoUpdate: cfg.GeoAutoUpdate,
GeoUpdateInterval: cfg.GeoUpdateInterval,
GeodataMode: cfg.GeodataMode,
GeodataLoader: cfg.GeodataLoader,
GeositeMatcher: cfg.GeositeMatcher,
TCPConcurrent: cfg.TCPConcurrent,
FindProcessMode: cfg.FindProcessMode,
GlobalUA: cfg.GlobalUA,
ETagSupport: cfg.ETagSupport,
KeepAliveIdle: cfg.KeepAliveIdle,
KeepAliveInterval: cfg.KeepAliveInterval,
DisableKeepAlive: cfg.DisableKeepAlive,
GeoAutoUpdate: cfg.GeoAutoUpdate,
GeoUpdateInterval: cfg.GeoUpdateInterval,
GeodataMode: cfg.GeodataMode,
GeodataLoader: cfg.GeodataLoader,
GeositeMatcher: cfg.GeositeMatcher,
TCPConcurrent: cfg.TCPConcurrent,
ProviderLoadConcurrency: cfg.ProviderLoadConcurrency,
FindProcessMode: cfg.FindProcessMode,
GlobalUA: cfg.GlobalUA,
ETagSupport: cfg.ETagSupport,
KeepAliveIdle: cfg.KeepAliveIdle,
KeepAliveInterval: cfg.KeepAliveInterval,
DisableKeepAlive: cfg.DisableKeepAlive,
}, nil
}

Expand Down
15 changes: 11 additions & 4 deletions hub/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ func ApplyConfig(cfg *config.Config, force bool) {
tunnel.OnInnerLoading()

initInnerTcp()
loadProvider(cfg.Providers)
providerLoadConcurrency := cfg.General.ProviderLoadConcurrency
loadProvider(cfg.Providers, providerLoadConcurrency)
updateProfile(cfg)
loadProvider(cfg.RuleProviders)
loadProvider(cfg.RuleProviders, providerLoadConcurrency)
runtime.GC()
tunnel.OnRunning()
updateUpdater(cfg)
Expand Down Expand Up @@ -315,7 +316,7 @@ func updateRules(rules []C.Rule, subRules map[string][]C.Rule, ruleProviders map
tunnel.UpdateRules(rules, subRules, ruleProviders)
}

func loadProvider[T P.Provider](providers map[string]T) {
func loadProvider[T P.Provider](providers map[string]T, concurrency int) {
load := func(pv T) {
name := pv.Name()
if pv.VehicleType() == P.Compatible {
Expand All @@ -338,8 +339,14 @@ func loadProvider[T P.Provider](providers map[string]T) {
}
}

if concurrency <= 0 {
concurrency = concurrentCount
} else {
log.Infoln("Use provider load concurrency: %d", concurrency)
}

wg := sync.WaitGroup{}
ch := make(chan struct{}, concurrentCount)
ch := make(chan struct{}, concurrency)
for _, pv := range providers {
pv := pv
wg.Add(1)
Expand Down
19 changes: 19 additions & 0 deletions hub/executor/provider_load_concurrency_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package executor

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestProviderLoadConcurrencyConfig(t *testing.T) {
config, err := ParseWithBytes([]byte("provider-load-concurrency: 1\n"))
require.NoError(t, err)
require.Equal(t, 1, config.General.ProviderLoadConcurrency)
}

func TestProviderLoadConcurrencyDefaultsToArchitectureValue(t *testing.T) {
config, err := ParseWithBytes([]byte(""))
require.NoError(t, err)
require.Zero(t, config.General.ProviderLoadConcurrency)
}