Skip to content

Commit

Permalink
Better defaults / estimates
Browse files Browse the repository at this point in the history
  • Loading branch information
junderw committed Oct 25, 2023
1 parent 14777f1 commit d19bc25
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hibp_downloader"
version = "1.0.1"
version = "1.0.2"
license = "MIT"
authors = [
"Jonathan Underwood <[email protected]>"
Expand Down
8 changes: 7 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct Config {
#[arg(long, default_value_t = default_workers())]
pub workers: usize,
/// The number of requests per worker
#[arg(long, default_value = "20")]
#[arg(long, default_value_t = default_multiplier())]
pub multiplier: usize,
/// Download NTLM hashes instead of SHA1 hashes
#[arg(short, long)]
Expand Down Expand Up @@ -69,6 +69,12 @@ fn default_workers() -> usize {
.get()
}

fn default_multiplier() -> usize {
// Cloudflare seems to throttle at 128 in-flight connections at a time
// (Note: available_parallelism is guaranteed to be non-zero)
128 / default_workers()
}

/// This function gives a static reference to a Config struct.
pub fn get_config<'a>() -> &'a Config {
static CONFIG: OnceLock<Config> = OnceLock::new();
Expand Down
4 changes: 2 additions & 2 deletions src/sort/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub fn run_sort(input: &Path, output: &Path, temp_dir: &Path) -> anyhow::Result<
assert!(len == 32 || len == 40);
len
};
// colon + average of 3 length number (max 8, min 1) + new line
let row_size = hash_size + 5;
// colon + average of 5 length number (max 8, min 1) + new line
let row_size = hash_size + 7;
let rows_in_file = input_byte_size / row_size as u64;

// This is a rough estimate.
Expand Down

0 comments on commit d19bc25

Please sign in to comment.