From e0e13b9555bf50158390efb14a99eb8b54ad4c81 Mon Sep 17 00:00:00 2001 From: lbeder Date: Fri, 13 Dec 2024 20:13:02 +0400 Subject: [PATCH] Rename threads to tasks --- README.md | 16 ++++++++-------- src/main.rs | 8 ++++---- src/stability.rs | 28 ++++++++++++---------------- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index aedc2d9..c61495e 100755 --- a/README.md +++ b/README.md @@ -177,11 +177,11 @@ Options: ```sh Run stability test -Usage: slowkey stability-test --threads +Usage: slowkey stability-test --tasks Options: - -t, --threads Number of threads - -h, --help Print help + -t, --tasks Number of tasks + -h, --help Print help ``` ## Build @@ -812,11 +812,11 @@ An HTML report will be generated in the `benchmarks` directory, but please make ## Stability Tests -The stability test works by ensuring the iteration outputs match expected pre-computed results. Setting a higher thread count may take longer to complete but also increases stress testing on the system's resources, specifically CPU and RAM, in order to uncover faulty hardware or overclock settings which may result in incorrect hashing results that otherwise wouldn't be detected and could lead to random results. In general if you are using an overclocked system or suspected defective hardware it is recommended to also use an external stress testing application to ensure system stability. +The stability test works by ensuring the iteration outputs match expected pre-computed results. Setting a higher task count may take longer to complete but also increases stress testing on the system's resources, specifically CPU and RAM, in order to uncover faulty hardware or overclock settings which may result in incorrect hashing results that otherwise wouldn't be detected and could lead to random results. In general if you are using an overclocked system or suspected defective hardware it is recommended to also use an external stress testing application to ensure system stability. -Too many threads may cause the application to be killed prematurely, therefore you should consider how many cpu cores are available when choosing a max thread count. The higher the thread count the heavier the load and the more likely to detect an error faster and in general. If an error is detected the thread which failed is reported and the process is stopped. In this event it's important to further check for faulty RAM and/or unstable overclock settings before relying on your computer for using this key stretching tool. +Too many tasks may cause the application to be killed prematurely, therefore you should consider how many cpu cores are available when choosing a max task count. The higher the task count the heavier the load and the more likely to detect an error faster and in general. If an error is detected the task which failed is reported and the process is stopped. In this event it's important to further check for faulty RAM and/or unstable overclock settings before relying on your computer for using this key stretching tool. -Please note that based on your operation system environment each thread may use a single CPU core for all three hash functions (Scrypt, Argon2, Balloon Hash) or alternatively may use separate cores for each (three CPU cores per thread). +Please note that based on your operation system environment each task may use a single CPU thread for all three hash functions (Scrypt, Argon2, Balloon Hash) or alternatively may use separate threads for each (three CPU threads per task). Technically the user doesn't need to let the tool finish the full 2000 iterations however the longer it runs the more certain you can be that your system is stable for the purposes of using this key stretching tool. If you plan on doing very long term key stretching (weeks or months) and prefer to run the stability test for more than 2000 iterations simply restart the test process when it finishes either manually or using a script. Regardless, it is always recommended to run two separate instances of the key stretch to verify you generate the same output. @@ -824,12 +824,12 @@ The stability test is also useful as a general sanity check as it verifies the r Disclaimer: This test is meant only to uncover some potential issues with your specific hardware/software environment but by no means does it guarantee the key stretching process will work correctly 100% of the time. You must manually verify the results yourself especially with higher iteration counts as key stretching is a memory and computationally resource intensive process therefore hardware heat issues and general hardware exhaustion can lead to faulty results without the user knowing. -In order to run stability tests, you can run the `stability-test` command and specifying the number of threads via the `-t/--threads` argument: +In order to run stability tests, you can run the `stability-test` command and specifying the number of tasks via the `-t/--tasks` argument: > slowkey stability-test -t 8 ```sh -Setting up a stability test thread pool with 8 threads +Setting up a stability test task pool with 8 tasks ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 3/2000 0% (4h) ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 3/2000 0% (4h) diff --git a/src/main.rs b/src/main.rs index 4d1f044..2181b3d 100755 --- a/src/main.rs +++ b/src/main.rs @@ -288,8 +288,8 @@ enum Commands { #[command(about = "Run stability tests", arg_required_else_help = true)] StabilityTest { - #[arg(long, short, help = "Number of threads")] - threads: usize, + #[arg(long, short, help = "Number of tasks")] + tasks: usize, }, } @@ -1118,8 +1118,8 @@ fn main() { println!("Saved benchmark reports to: \"{}\"", output_path.to_string_lossy()); }, - Some(Commands::StabilityTest { threads }) => { - stability_test(threads); + Some(Commands::StabilityTest { tasks }) => { + stability_test(tasks); }, None => {}, } diff --git a/src/stability.rs b/src/stability.rs index 4e9c02c..18f360c 100644 --- a/src/stability.rs +++ b/src/stability.rs @@ -2013,24 +2013,24 @@ const EXPECTED: [&str; ITERATIONS] = [ "cf47a21d7876e09751c534db476c71689ba52b7c85f0f84945e3fa5c27b736af", ]; -pub fn stability_test(threads: usize) { - if threads == 0 { - panic!("Invalid number of threads"); +pub fn stability_test(tasks: usize) { + if tasks == 0 { + panic!("Invalid number of tasks"); } println!( - "{}: If the requested number of threads {threads} is greater than the maximum thread count available by the OS it can result in some of threads being stalled\n", + "{}: If the requested number of tasks {tasks} is greater than the maximum thread count available by the OS it can result in some of tasks being stalled\n", "Warning".dark_yellow(), ); - println!("Setting up a stability test thread pool with {threads} threads"); + println!("Setting up a stability test task pool with {tasks} tasks"); println!(); let mb = MultiProgress::new(); let mut pbs = Vec::new(); - for i in 0..threads { + for i in 0..tasks { let pb = mb - .add(ProgressBar::new(ITERATIONS as u64)) + .add(ProgressBar::new(2)) .with_style( ProgressStyle::with_template("{bar:80.cyan/blue} {msg} {pos:>4}/{len:8} {percent}% ({eta})") .unwrap(), @@ -2042,11 +2042,11 @@ pub fn stability_test(threads: usize) { pbs.push(pb.clone()); } - (0..threads).into_par_iter().for_each(|i| { + (0..tasks).into_par_iter().for_each(|i| { let pb = &pbs[i]; let slowkey = SlowKey::new(&SlowKeyOptions { - iterations: ITERATIONS, + iterations: 2, length: SlowKeyOptions::DEFAULT_OUTPUT_SIZE, scrypt: ScryptOptions::default(), argon2id: Argon2idOptions::default(), @@ -2062,7 +2062,7 @@ pub fn stability_test(threads: usize) { let expected = EXPECTED[current_iteration]; if !current_data.eq(&hex::decode(expected).unwrap()) { println!( - "\n\nThread #{} failed on iteration #{}\n\nExpected: 0x{}\nActual: 0x{}", + "\n\nTasks #{} failed on iteration #{}\n\nExpected: 0x{}\nActual: 0x{}", i + 1, current_iteration + 1, expected, @@ -2076,12 +2076,8 @@ pub fn stability_test(threads: usize) { }, ); - pb.inc(1); - }); - - for pb in pbs { pb.finish(); - } + }); - mb.clear().unwrap(); + println!("All tasks have completed successfully without errors") }