From 7f47772dcb967103a6b2d3f9a9abc3d769b96a03 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Sat, 26 Jun 2021 00:54:39 +0100 Subject: [PATCH] Limit tokio threads --- src/main.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8ef97a1..0a054b3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,23 +56,32 @@ struct Opts { overwrite: bool, } -#[tokio::main] -async fn main() -> anyhow::Result<()> { +fn main() -> anyhow::Result<()> { pretty_env_logger::init(); - let opts = Opts::parse(); + let rt = tokio::runtime::Builder::new_multi_thread() + .enable_all() + // the default is 512, it can get out of hand. + .max_blocking_threads(8) + .build()?; - let torrent = - if opts.torrent_path.starts_with("http://") || opts.torrent_path.starts_with("https://") { + rt.block_on(async move { + let opts = Opts::parse(); + + let torrent = if opts.torrent_path.starts_with("http://") + || opts.torrent_path.starts_with("https://") + { torrent_from_url(&opts.torrent_path).await? } else { torrent_from_file(&opts.torrent_path)? }; - info!("Torrent metadata: {:#?}", &torrent); + info!("Torrent metadata: {:#?}", &torrent); - let builder = TorrentManagerBuilder::new(torrent, opts.output_folder).overwrite(opts.overwrite); - let manager_handle = builder.start_manager().await?; - manager_handle.wait_until_completed().await?; - Ok(()) + let builder = + TorrentManagerBuilder::new(torrent, opts.output_folder).overwrite(opts.overwrite); + let manager_handle = builder.start_manager().await?; + manager_handle.wait_until_completed().await?; + Ok(()) + }) }