use thread pool for non-index hash calculations (#15149)
This commit is contained in:
committed by
GitHub
parent
6fd5ec0e4c
commit
fabecdc86c
@ -983,7 +983,7 @@ impl ShrinkStats {
|
||||
}
|
||||
}
|
||||
|
||||
fn make_min_priority_thread_pool() -> ThreadPool {
|
||||
pub fn make_min_priority_thread_pool() -> ThreadPool {
|
||||
// Use lower thread count to reduce priority.
|
||||
let num_threads = std::cmp::max(2, num_cpus::get() / 4);
|
||||
rayon::ThreadPoolBuilder::new()
|
||||
@ -3748,6 +3748,7 @@ impl AccountsDB {
|
||||
Self::calculate_accounts_hash_without_index(
|
||||
&combined_maps,
|
||||
simple_capitalization_enabled,
|
||||
&self.thread_pool_clean,
|
||||
)
|
||||
} else {
|
||||
self.calculate_accounts_hash(slot, ancestors, false, simple_capitalization_enabled)
|
||||
@ -3851,10 +3852,13 @@ impl AccountsDB {
|
||||
pub fn calculate_accounts_hash_without_index(
|
||||
storages: &[SnapshotStorage],
|
||||
simple_capitalization_enabled: bool,
|
||||
thread_pool: &ThreadPool,
|
||||
) -> (Hash, u64) {
|
||||
let result = Self::scan_snapshot_stores(storages, simple_capitalization_enabled);
|
||||
thread_pool.install(|| {
|
||||
let result = Self::scan_snapshot_stores(storages, simple_capitalization_enabled);
|
||||
|
||||
Self::rest_of_hash_calculation(result)
|
||||
Self::rest_of_hash_calculation(result)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn verify_bank_hash_and_lamports(
|
||||
@ -5180,7 +5184,11 @@ pub mod tests {
|
||||
solana_logger::setup();
|
||||
|
||||
let (storages, _size, _slot_expected) = sample_storage();
|
||||
let result = AccountsDB::calculate_accounts_hash_without_index(&storages, true);
|
||||
let result = AccountsDB::calculate_accounts_hash_without_index(
|
||||
&storages,
|
||||
true,
|
||||
&make_min_priority_thread_pool(),
|
||||
);
|
||||
let expected_hash = Hash::from_str("GKot5hBsd81kMupNCXHaqbhv3huEbxAFMLnpcX2hniwn").unwrap();
|
||||
assert_eq!(result, (expected_hash, 0));
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ use crate::{
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
use itertools::Itertools;
|
||||
use log::*;
|
||||
use rayon::ThreadPool;
|
||||
use solana_measure::measure::Measure;
|
||||
use solana_metrics::{datapoint_debug, inc_new_counter_debug, inc_new_counter_info};
|
||||
use solana_sdk::{
|
||||
@ -4307,6 +4308,10 @@ impl Bank {
|
||||
self.rc.accounts.accounts_db.get_accounts_hash(self.slot)
|
||||
}
|
||||
|
||||
pub fn get_thread_pool(&self) -> &ThreadPool {
|
||||
&self.rc.accounts.accounts_db.thread_pool_clean
|
||||
}
|
||||
|
||||
pub fn update_accounts_hash_with_index_option(
|
||||
&self,
|
||||
do_not_use_index: bool,
|
||||
|
@ -15,6 +15,7 @@ use bincode::{config::Options, serialize_into};
|
||||
use bzip2::bufread::BzDecoder;
|
||||
use flate2::read::GzDecoder;
|
||||
use log::*;
|
||||
use rayon::ThreadPool;
|
||||
use regex::Regex;
|
||||
use solana_measure::measure::Measure;
|
||||
use solana_sdk::{clock::Slot, genesis_config::GenesisConfig, hash::Hash, pubkey::Pubkey};
|
||||
@ -926,6 +927,7 @@ pub fn bank_to_snapshot_archive<P: AsRef<Path>, Q: AsRef<Path>>(
|
||||
snapshot_version: Option<SnapshotVersion>,
|
||||
snapshot_package_output_path: Q,
|
||||
archive_format: ArchiveFormat,
|
||||
thread_pool: &ThreadPool,
|
||||
) -> Result<PathBuf> {
|
||||
let snapshot_version = snapshot_version.unwrap_or_default();
|
||||
|
||||
@ -952,13 +954,16 @@ pub fn bank_to_snapshot_archive<P: AsRef<Path>, Q: AsRef<Path>>(
|
||||
None,
|
||||
)?;
|
||||
|
||||
let package = process_accounts_package_pre(package);
|
||||
let package = process_accounts_package_pre(package, Some(&thread_pool));
|
||||
|
||||
archive_snapshot_package(&package)?;
|
||||
Ok(package.tar_output_file)
|
||||
}
|
||||
|
||||
pub fn process_accounts_package_pre(accounts_package: AccountsPackagePre) -> AccountsPackage {
|
||||
pub fn process_accounts_package_pre(
|
||||
accounts_package: AccountsPackagePre,
|
||||
thread_pool: Option<&ThreadPool>,
|
||||
) -> AccountsPackage {
|
||||
let mut time = Measure::start("hash");
|
||||
|
||||
let hash = accounts_package.hash; // temporarily remaining here
|
||||
@ -966,6 +971,7 @@ pub fn process_accounts_package_pre(accounts_package: AccountsPackagePre) -> Acc
|
||||
let (hash, lamports) = AccountsDB::calculate_accounts_hash_without_index(
|
||||
&accounts_package.storages,
|
||||
accounts_package.simple_capitalization_testing,
|
||||
&thread_pool.unwrap(),
|
||||
);
|
||||
|
||||
assert_eq!(accounts_package.expected_capitalization, lamports);
|
||||
|
Reference in New Issue
Block a user