Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
configure threads with env var
  • Loading branch information
liamaharon committed Apr 27, 2023
commit 455bb5cf8c0a55f47eba8c93fe0d3ff968420c8b
18 changes: 9 additions & 9 deletions utils/frame/remote-externalities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ use sp_core::{
pub use sp_io::TestExternalities;
use sp_runtime::{traits::Block as BlockT, StateVersion};
use std::{
cmp::{max, min},
cmp::max,
fs,
num::NonZeroUsize,
ops::{Deref, DerefMut},
path::{Path, PathBuf},
sync::Arc,
thread,
};
use substrate_rpc_client::{rpc_params, BatchRequestBuilder, ChainApi, ClientT, StateApi};

Expand Down Expand Up @@ -327,7 +326,7 @@ where
B::Hash: DeserializeOwned,
B::Header: DeserializeOwned,
{
const MAX_PARALLELISM: usize = 4;
const DEFAULT_PARALLELISM: usize = 4;
const BATCH_SIZE_INCREASE_FACTOR: f32 = 1.10;
const BATCH_SIZE_DECREASE_FACTOR: f32 = 0.50;
const INITIAL_BATCH_SIZE: usize = 5000;
Expand All @@ -338,12 +337,13 @@ where
/// Cap the number of threads. Performance improvement beyond a small number of threads is
/// negligible, and too many threads can create issues with the HttpClient.
fn threads() -> NonZeroUsize {
let avaliable = thread::available_parallelism()
.unwrap_or(NonZeroUsize::new(1usize).expect("1 is non-zero; qed"))
.get();
assert!(avaliable > 0, "avaliable parallelism must be greater than 0");
return NonZeroUsize::new(min(avaliable, Self::MAX_PARALLELISM))
.expect("avaliable is non-zero and MAX_PARRELISM is non-zero; qed")
let threads: usize = match std::env::var("TRY_RUNTIME_MAX_THREADS") {
Ok(n) => n.parse::<usize>().expect("TRY_RUNTIME_MAX_THREADS must be a number"),
Err(_) => Self::DEFAULT_PARALLELISM,
};
assert!(threads > 0, "TRY_RUNTIME_MAX_THREADS must be greater than 0");
dbg!(threads);
return NonZeroUsize::new(threads).expect("threads is non-zero; qed")
}

async fn rpc_get_storage(
Expand Down