mirror of
https://github.com/eycorsican/leaf.git
synced 2026-12-05 16:02:32 +00:00
bin: allow specifying the number of runtime worker threads
This commit is contained in:
1 parent
034b7d8af3
commit
fc3cea4e67
2 files changed
+31
-13
No files matched your search
+1
-3
@@ -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
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user