Skip to content

Commit

Permalink
Merge pull request #647 from hatoo/num-physical-cores
Browse files Browse the repository at this point in the history
Use number of physical cores workers because it's more performant empirically.
  • Loading branch information
hatoo authored Jan 4, 2025
2 parents c1ce2ca + 58359e6 commit 4552ecf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ http-body-util = "0.1.2"
hyper-util = { version = "0.1.6", features = ["tokio"] }
tokio-vsock = { version = "0.5.0", optional = true }
rusqlite = { version = "0.32.0", features = ["bundled"] }
num_cpus = "1.16.0"

[target.'cfg(unix)'.dependencies]
rlimit = "0.10.1"
Expand Down
18 changes: 16 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ impl FromStr for VsockAddr {
}
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
async fn run() -> anyhow::Result<()> {
let mut opts: Opts = Opts::parse();

let parse_http_version = |is_http2: bool, version: Option<&str>| match (is_http2, version) {
Expand Down Expand Up @@ -758,3 +757,18 @@ fn system_resolv_conf() -> anyhow::Result<(ResolverConfig, ResolverOpts)> {
hickory_resolver::system_conf::read_system_conf()
.context("DNS: failed to load /etc/resolv.conf")
}

fn main() {
let num_workers_threads = std::env::var("TOKIO_WORKER_THREADS")
.ok()
.and_then(|s| s.parse().ok())
// Prefer to use physical cores rather than logical one because it's more performant empirically.
.unwrap_or(num_cpus::get_physical());

let rt = tokio::runtime::Builder::new_multi_thread()
.worker_threads(num_workers_threads)
.enable_all()
.build()
.unwrap();
rt.block_on(run()).unwrap();
}

0 comments on commit 4552ecf

Please sign in to comment.