From 70e69a382e7a44ef3446c22139f07c466812daf2 Mon Sep 17 00:00:00 2001 From: "Sijie.Sun" Date: Thu, 26 Jun 2025 02:19:33 +0800 Subject: [PATCH] allow set multithread count (#1056) --- easytier/locales/app.yml | 6 ++++++ easytier/src/common/config.rs | 1 + easytier/src/easytier-core.rs | 8 ++++++++ easytier/src/launcher.rs | 3 ++- easytier/src/proto/common.proto | 2 ++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/easytier/locales/app.yml b/easytier/locales/app.yml index fd84007..84afdd6 100644 --- a/easytier/locales/app.yml +++ b/easytier/locales/app.yml @@ -92,6 +92,9 @@ core_clap: multi_thread: en: "use multi-thread runtime, default is single-thread" zh-CN: "使用多线程运行时,默认为单线程" + multi_thread_count: + en: "the number of threads to use, default is 2, only effective when multi-thread is enabled, must be greater than 2" + zh-CN: "使用的线程数,默认为2,仅在多线程模式下有效。取值必须大于2" disable_ipv6: en: "do not use ipv6" zh-CN: "不使用IPv6" @@ -178,6 +181,9 @@ core_clap: private_mode: en: "if true, nodes with different network names or passwords from this network are not allowed to perform handshake or relay through this node." zh-CN: "如果为true,则不允许使用了与本网络不相同的网络名称和密码的节点通过本节点进行握手或中转" + foreign_relay_bps_limit: + en: "the maximum bps limit for foreign network relay, default is no limit. unit: BPS (bytes per second)" + zh-CN: "作为共享节点时,限制非本地网络的流量转发速率,默认无限制,单位 BPS (字节每秒)" core_app: panic_backtrace_save: diff --git a/easytier/src/common/config.rs b/easytier/src/common/config.rs index 1c1e8bf..41d6390 100644 --- a/easytier/src/common/config.rs +++ b/easytier/src/common/config.rs @@ -43,6 +43,7 @@ pub fn gen_default_flags() -> Flags { enable_quic_proxy: false, disable_quic_input: false, foreign_relay_bps_limit: u64::MAX, + multi_thread_count: 2, } } diff --git a/easytier/src/easytier-core.rs b/easytier/src/easytier-core.rs index 9866b5e..f67d7fa 100644 --- a/easytier/src/easytier-core.rs +++ b/easytier/src/easytier-core.rs @@ -276,6 +276,13 @@ struct NetworkOptions { )] multi_thread: Option, + #[arg( + long, + env = "ET_MULTI_THREAD_COUNT", + help = t!("core_clap.multi_thread_count").to_string(), + )] + multi_thread_count: Option, + #[arg( long, env = "ET_DISABLE_IPV6", @@ -819,6 +826,7 @@ impl NetworkOptions { f.foreign_relay_bps_limit = self .foreign_relay_bps_limit .unwrap_or(f.foreign_relay_bps_limit); + f.multi_thread_count = self.multi_thread_count.unwrap_or(f.multi_thread_count); cfg.set_flags(f); if !self.exit_nodes.is_empty() { diff --git a/easytier/src/launcher.rs b/easytier/src/launcher.rs index bfbd6af..cdfe7ec 100644 --- a/easytier/src/launcher.rs +++ b/easytier/src/launcher.rs @@ -256,8 +256,9 @@ impl EasyTierLauncher { self.thread_handle = Some(std::thread::spawn(move || { let rt = if cfg.get_flags().multi_thread { + let worker_threads = 2.max(cfg.get_flags().multi_thread_count as usize); tokio::runtime::Builder::new_multi_thread() - .worker_threads(2) + .worker_threads(worker_threads) .enable_all() .build() } else { diff --git a/easytier/src/proto/common.proto b/easytier/src/proto/common.proto index c9761e9..bd6cef0 100644 --- a/easytier/src/proto/common.proto +++ b/easytier/src/proto/common.proto @@ -43,6 +43,8 @@ message FlagsInConfig { // a global relay limit, only work for foreign network uint64 foreign_relay_bps_limit = 26; + + uint32 multi_thread_count = 27; } message RpcDescriptor {