diff --git a/go.mod b/go.mod index f2a36c55..7da56c9e 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/yaling888/go-lwip v0.0.0-20210928231210-94b50cb51cc1 go.etcd.io/bbolt v1.3.6 go.uber.org/atomic v1.9.0 + go.uber.org/automaxprocs v1.4.0 golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f golang.org/x/sync v0.0.0-20210220032951-036812b2e83c diff --git a/go.sum b/go.sum index fb3f103c..148e812a 100644 --- a/go.sum +++ b/go.sum @@ -599,6 +599,8 @@ go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/automaxprocs v1.4.0 h1:CpDZl6aOlLhReez+8S3eEotD7Jx0Os++lemPlMULQP0= +go.uber.org/automaxprocs v1.4.0/go.mod h1:/mTEdr7LvHhs0v7mjdxDreTz1OG5zdZGqgOnhWiR/+Q= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= diff --git a/main.go b/main.go index 7691aded..d17e0246 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,8 @@ import ( "github.com/Dreamacro/clash/hub" "github.com/Dreamacro/clash/hub/executor" "github.com/Dreamacro/clash/log" + + "go.uber.org/automaxprocs/maxprocs" ) var ( @@ -44,6 +46,7 @@ func init() { } func main() { + maxprocs.Set(maxprocs.Logger(func(string, ...interface{}) {})) if version { fmt.Printf("Clash Plus Pro %s %s %s with %s %s\n", C.Version, runtime.GOOS, runtime.GOARCH, runtime.Version(), C.BuildTime) return diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 1aaf94f4..73b2b499 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -102,8 +102,8 @@ func processUDP() { func process() { numUDPWorkers := 4 - if runtime.NumCPU() > numUDPWorkers { - numUDPWorkers = runtime.NumCPU() + if num := runtime.GOMAXPROCS(0); num > numUDPWorkers { + numUDPWorkers = num } for i := 0; i < numUDPWorkers; i++ { go processUDP()