bin: allow specifying the number of runtime worker threads

This commit is contained in:
eric committed 2021-02-25 14:13:44 +08:00
1 parent 034b7d8af3
commit fc3cea4e67
2 files changed
+31 -13

No files matched your search

+1 -3
View File
@@ -27,12 +27,10 @@ default-openssl = [
"leaf/openssl-tls",
]
multi-thread = ["tokio/rt-threaded"]
[dependencies]
leaf = { path = "../leaf", default-features = false, optional = true }
clap = { version = "3.0.0-beta.1", default-features = false, features =["std"] }
log = { version = "0.4", features = ["std"] }
fern = { version = "0.5", features = ["colored"] }
tokio = { version = "0.2", features = ["signal"] }
tokio = { version = "0.2", features = ["signal", "rt-threaded"] }
futures = "0.3"
+30 -10
View File
@@ -30,6 +30,14 @@ fn main() {
.takes_value(true)
.default_value("config.conf"),
)
.arg(
Arg::new("threads")
.long("threads")
.value_name("N")
.about("Specifies the number of runtime threads. Note that the default Tokio runtime worker thread stack size is 2MB.")
.takes_value(true)
.default_value("auto"),
)
.arg(
Arg::new("test-outbound")
.short('t')
@@ -51,21 +59,33 @@ fn main() {
};
let mut rt = {
#[cfg(feature = "multi-thread")]
{
let threads = matches.value_of("threads").unwrap();
if threads == "auto" {
tokio::runtime::Builder::new()
.threaded_scheduler()
.enable_all()
.build()
.unwrap()
}
#[cfg(not(feature = "multi-thread"))]
{
tokio::runtime::Builder::new()
.basic_scheduler()
.enable_all()
.build()
.unwrap()
} else {
if let Ok(n) = threads.parse::<usize>() {
if n > 1 {
tokio::runtime::Builder::new()
.threaded_scheduler()
.core_threads(n)
.enable_all()
.build()
.unwrap()
} else {
tokio::runtime::Builder::new()
.basic_scheduler()
.enable_all()
.build()
.unwrap()
}
} else {
println!("invalid number of threads");
exit(1);
}
}
};