Skip to content

Commit

Permalink
Rename threads to tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeder committed Dec 13, 2024
1 parent 079eb60 commit e0e13b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ Options:
```sh
Run stability test

Usage: slowkey stability-test --threads <THREADS>
Usage: slowkey stability-test --tasks <THREADS>

Options:
-t, --threads <THREADS> Number of threads
-h, --help Print help
-t, --tasks <THREADS> Number of tasks
-h, --help Print help
```
## Build
Expand Down Expand Up @@ -812,24 +812,24 @@ 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.
The stability test is also useful as a general sanity check as it verifies the results match correct pre-computed outputs, however it is not a replacement for manually verifying the results yourself by running the key stretching process with the same parameters a second time (or running two stretches in parallel assuming you have a large number of iterations and want to save time). Technically this can be done on the same computer but for the truly paranoid it's recommended to use a separate setup.
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)
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down Expand Up @@ -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 => {},
}
Expand Down
28 changes: 12 additions & 16 deletions src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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,
Expand All @@ -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")
}

0 comments on commit e0e13b9

Please sign in to comment.