Add a jobs parameter to set the number of threads the indexer uses

This commit is contained in:
Kerollmops 2020-06-28 12:13:10 +02:00
parent 2a3b03138b
commit adb1038b26
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -46,6 +46,10 @@ struct Opt {
#[structopt(long, default_value = "100000")] #[structopt(long, default_value = "100000")]
arc_cache_size: usize, arc_cache_size: usize,
/// Number of parallel jobs, defaults to # of CPUs.
#[structopt(short, long)]
jobs: Option<usize>,
/// CSV file to index. /// CSV file to index.
csv_file: PathBuf, csv_file: PathBuf,
} }
@ -468,6 +472,10 @@ fn open_env_index(path: impl AsRef<Path>) -> anyhow::Result<(Env, Index)> {
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
let opt = Opt::from_args(); let opt = Opt::from_args();
if let Some(jobs) = opt.jobs {
rayon::ThreadPoolBuilder::new().num_threads(jobs).build_global()?;
}
std::fs::create_dir_all(&opt.database)?; std::fs::create_dir_all(&opt.database)?;
let (env, index) = open_env_index(&opt.database)?; let (env, index) = open_env_index(&opt.database)?;