From 9cb4ba6bf2f025b1cd5a0447c4f9c1b0b88f093f Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Wed, 15 Jan 2025 07:10:23 +0100 Subject: [PATCH] improve cli handling --- src/main.rs | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index a21c932..04fbd6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,15 +25,30 @@ struct Args { name: PathBuf, #[arg(short, long)] url: String, - #[arg(short, long)] - buffer: Option, - #[arg(short, long)] - rate: Option, - #[arg(short, long)] - concurrency: Option, - #[arg(short, long)] - timeout: Option, - #[arg(short = 'B', default_value_t = false, help = "use body timeout")] + #[arg( short + , long + , default_value_t = 10 + , help = "request to store in client after \ + concurrency limit reached" )] + buffer: usize, + #[arg( short + , long + , default_value_t = 40 + , help = "number of requests per second the client should perform" )] + rate: u64, + #[arg( short + , long + , default_value_t = 20 + , help = "number of concurrent requests" )] + concurrency: usize, + #[arg( short + , long + , default_value_t = 30 + , help = "network io timeout" )] + timeout: u64, + #[arg( short = 'B' + , default_value_t = false + , help = "also use timeout on body reads" )] use_body_timeout: bool, #[arg( short , default_value_t = 301 @@ -73,11 +88,7 @@ async fn main() -> anyhow::Result<()> { Err(anyhow!("Only filenames with .mp4 extension are allowed"))? } - let buffer = args.buffer.unwrap_or(20); - let rate_limit = args.rate.unwrap_or(20); - let concurrency_limit = args.concurrency.unwrap_or(20); - let timeout = args.timeout.unwrap_or(15); - let timeout = Duration::from_secs(timeout); + let timeout = Duration::from_secs(args.timeout); let wait_time = Duration::from_secs(args.wait); let body_timeout = if args.use_body_timeout { Some(timeout) @@ -93,7 +104,7 @@ async fn main() -> anyhow::Result<()> { info!("Creating an HTTP client with Tower layers..."); - let client = Client::new(buffer, rate_limit, concurrency_limit, timeout)? + let client = Client::new(args.buffer, args.rate, args.concurrency, timeout)? . set_body_timeout(body_timeout) . set_origin(args.origin)?; @@ -103,7 +114,7 @@ async fn main() -> anyhow::Result<()> { client }; - let actor = ClientActorHandle::new(client, buffer + concurrency_limit); + let actor = ClientActorHandle::new(client, args.buffer + args.concurrency); info!("Get segments...");