Skip to content

Commit bc5ffdd

Browse files
author
Ludo Galabru
committed
feat: in-house thread pool
1 parent 2f172e0 commit bc5ffdd

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

components/hord-cli/src/db/mod.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,8 @@ pub async fn rebuild_rocks_db(
23262326
let moved_bitcoin_network = moved_bitcoin_network.clone();
23272327
compress_block_data_pool.execute(move || {
23282328
while let Ok(Some(block_bytes)) = rx.recv() {
2329-
let raw_block_data = parse_downloaded_block(block_bytes).expect("unable to parse block");
2329+
let raw_block_data =
2330+
parse_downloaded_block(block_bytes).expect("unable to parse block");
23302331
let compressed_block = LazyBlock::from_full_block(&raw_block_data)
23312332
.expect("unable to compress block");
23322333
let block_data = hord::parse_ordinals_and_standardize_block(
@@ -2422,12 +2423,7 @@ pub async fn rebuild_rocks_db(
24222423
thread_index = (thread_index + 1) % hord_config.ingestion_thread_max;
24232424
}
24242425

2425-
ctx.try_log(|logger| {
2426-
info!(
2427-
logger,
2428-
"Gargbage collecting will start"
2429-
)
2430-
});
2426+
ctx.try_log(|logger| info!(logger, "Gargbage collecting will start"));
24312427

24322428
for tx in tx_thread_pool.iter() {
24332429
let _ = tx.send(None);
@@ -2436,12 +2432,7 @@ pub async fn rebuild_rocks_db(
24362432
let _ = storage_thread.join();
24372433
let _ = set.shutdown();
24382434

2439-
ctx.try_log(|logger| {
2440-
info!(
2441-
logger,
2442-
"Gargbage collecting did finish"
2443-
)
2444-
});
2435+
ctx.try_log(|logger| info!(logger, "Gargbage collecting did finish"));
24452436

24462437
// match guard.report().build() {
24472438
// Ok(report) => {

components/hord-cli/src/hord/mod.rs

+30-21
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,8 @@ pub fn retrieve_inscribed_satoshi_points_from_block_v3(
11921192
let expected_traversals = transactions_ids.len() + l1_cache_hits.len();
11931193
let (traversal_tx, traversal_rx) = channel();
11941194

1195-
let traversal_data_pool = ThreadPool::new(thread_max);
11961195
let mut tx_thread_pool = vec![];
1196+
let mut thread_pool_handles = vec![];
11971197

11981198
for thread_index in 0..thread_max {
11991199
let (tx, rx) = channel();
@@ -1204,23 +1204,30 @@ pub fn retrieve_inscribed_satoshi_points_from_block_v3(
12041204
let moved_hord_db_path = hord_config.db_path.clone();
12051205
let local_cache = cache_l2.clone();
12061206

1207-
traversal_data_pool.execute(move || {
1208-
while let Ok(Some((transaction_id, block_identifier, input_index, prioritary))) =
1209-
rx.recv()
1210-
{
1211-
let traversal: Result<TraversalResult, String> =
1212-
retrieve_satoshi_point_using_lazy_storage_v3(
1213-
&moved_hord_db_path,
1214-
&block_identifier,
1215-
&transaction_id,
1216-
input_index,
1217-
0,
1218-
&local_cache,
1219-
&moved_ctx,
1220-
);
1221-
let _ = moved_traversal_tx.send((traversal, prioritary, thread_index));
1222-
}
1223-
});
1207+
let handle = hiro_system_kit::thread_named("Worker")
1208+
.spawn(move || {
1209+
while let Ok(Some((
1210+
transaction_id,
1211+
block_identifier,
1212+
input_index,
1213+
prioritary,
1214+
))) = rx.recv()
1215+
{
1216+
let traversal: Result<TraversalResult, String> =
1217+
retrieve_satoshi_point_using_lazy_storage_v3(
1218+
&moved_hord_db_path,
1219+
&block_identifier,
1220+
&transaction_id,
1221+
input_index,
1222+
0,
1223+
&local_cache,
1224+
&moved_ctx,
1225+
);
1226+
let _ = moved_traversal_tx.send((traversal, prioritary, thread_index));
1227+
}
1228+
})
1229+
.expect("unable to spawn thread");
1230+
thread_pool_handles.push(handle);
12241231
}
12251232

12261233
// Empty cache
@@ -1335,12 +1342,14 @@ pub fn retrieve_inscribed_satoshi_points_from_block_v3(
13351342
}
13361343
}
13371344
}
1338-
for thread_index in 0..thread_max {
1339-
let _ = tx_thread_pool[thread_index].send(None);
1345+
for tx in tx_thread_pool.iter() {
1346+
let _ = tx.send(None);
13401347
}
13411348

13421349
let _ = hiro_system_kit::thread_named("Garbage collection").spawn(move || {
1343-
let _ = traversal_data_pool.join();
1350+
for handle in thread_pool_handles.into_iter() {
1351+
let _ = handle.join();
1352+
}
13441353
});
13451354
} else {
13461355
ctx.try_log(|logger| {

0 commit comments

Comments
 (0)