Skip to content

Commit 807bb84

Browse files
committed
[mempool] rayon: use IO_POOL for accessing DB
1 parent 928cdc0 commit 807bb84

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

mempool/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ mod core_mempool;
7171
pub mod counters;
7272
mod logging;
7373
mod shared_mempool;
74+
pub(crate) mod thread_pool;

mempool/src/shared_mempool/tasks.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
//! Tasks that are executed by coordinators (short-lived compared to coordinators)
5+
use crate::thread_pool::IO_POOL;
56
use crate::{
67
core_mempool::{CoreMempool, TimelineState, TxnPointer},
78
counters,
@@ -235,16 +236,18 @@ where
235236

236237
let start_storage_read = Instant::now();
237238
// Track latency: fetching seq number
238-
let seq_numbers = transactions
239-
.par_iter()
240-
.map(|t| {
241-
get_account_sequence_number(smp.db.clone(), t.sender()).map_err(|e| {
242-
error!(LogSchema::new(LogEntry::DBError).error(&e));
243-
counters::DB_ERROR.inc();
244-
e
239+
let seq_numbers = IO_POOL.install(|| {
240+
transactions
241+
.par_iter()
242+
.map(|t| {
243+
get_account_sequence_number(smp.db.clone(), t.sender()).map_err(|e| {
244+
error!(LogSchema::new(LogEntry::DBError).error(&e));
245+
counters::DB_ERROR.inc();
246+
e
247+
})
245248
})
246-
})
247-
.collect::<Vec<_>>();
249+
.collect::<Vec<_>>()
250+
});
248251
// Track latency for storage read fetching sequence number
249252
let storage_read_latency = start_storage_read.elapsed();
250253
counters::PROCESS_TXN_BREAKDOWN_LATENCY

mempool/src/thread_pool.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) Aptos
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#![forbid(unsafe_code)]
5+
6+
use once_cell::sync::Lazy;
7+
8+
pub(crate) static IO_POOL: Lazy<rayon::ThreadPool> = Lazy::new(|| {
9+
rayon::ThreadPoolBuilder::new()
10+
.thread_name(|index| format!("mempool_io_{}", index))
11+
.build()
12+
.unwrap()
13+
});

0 commit comments

Comments
 (0)