Skip to content

Commit

Permalink
Merge pull request mempool#68 from mempool/junderw/threadpool-builder…
Browse files Browse the repository at this point in the history
…-fix

ThreadPoolBuilder can fail when resources are busy
  • Loading branch information
softsimon authored Feb 23, 2024
2 parents c1252cc + 8946212 commit cefb688
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,11 +1095,23 @@ fn lookup_txos(
outpoints: &BTreeSet<OutPoint>,
allow_missing: bool,
) -> HashMap<OutPoint, TxOut> {
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(16) // we need to saturate SSD IOPS
.thread_name(|i| format!("lookup-txo-{}", i))
.build()
.unwrap();
let mut loop_count = 10;
let pool = loop {
match rayon::ThreadPoolBuilder::new()
.num_threads(16) // we need to saturate SSD IOPS
.thread_name(|i| format!("lookup-txo-{}", i))
.build()
{
Ok(pool) => break pool,
Err(e) => {
if loop_count == 0 {
panic!("schema::lookup_txos failed to create a ThreadPool: {}", e);
}
std::thread::sleep(std::time::Duration::from_millis(50));
loop_count -= 1;
}
}
};
pool.install(|| {
outpoints
.par_iter()
Expand Down

0 comments on commit cefb688

Please sign in to comment.