Skip to content

Commit

Permalink
try-runtime-cli: improve ci stability (paritytech#14030)
Browse files Browse the repository at this point in the history
* hardcode 1 thread

* ci stability

* fix comment

* improve comment

* kick ci

* kick ci

* update expect message

* improve comment

* kick ci

* kick ci

* configure threads with env var

* fix threads env var

* fix threads env var
  • Loading branch information
liamaharon authored and nathanwhit committed Jul 19, 2023
1 parent d442d0e commit 6c7f53b
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions utils/frame/remote-externalities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use sp_core::{
pub use sp_io::TestExternalities;
use sp_runtime::{traits::Block as BlockT, StateVersion};
use std::{
cmp::max,
cmp::{max, min},
fs,
num::NonZeroUsize,
ops::{Deref, DerefMut},
Expand Down Expand Up @@ -157,10 +157,14 @@ impl Transport {
} else {
uri.clone()
};
let http_client = HttpClientBuilder::default().build(uri).map_err(|e| {
log::error!(target: LOG_TARGET, "error: {:?}", e);
"failed to build http client"
})?;
let http_client = HttpClientBuilder::default()
.max_request_body_size(u32::MAX)
.request_timeout(std::time::Duration::from_secs(60 * 5))
.build(uri)
.map_err(|e| {
log::error!(target: LOG_TARGET, "error: {:?}", e);
"failed to build http client"
})?;

*self = Self::RemoteClient(Arc::new(http_client))
}
Expand Down Expand Up @@ -323,16 +327,29 @@ where
B::Hash: DeserializeOwned,
B::Header: DeserializeOwned,
{
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;
// NOTE: increasing this value does not seem to impact speed all that much.
const DEFAULT_KEY_DOWNLOAD_PAGE: u32 = 1000;

/// Get the number of threads to use.
/// 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 {
thread::available_parallelism()
.unwrap_or(NonZeroUsize::new(1usize).expect("4 is non-zero; qed"))
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");

let requested: 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!(requested > 0, "TRY_RUNTIME_MAX_THREADS must be greater than 0");
return NonZeroUsize::new(min(requested, avaliable))
.expect("requested and avaliable are non-zero; qed")
}

async fn rpc_get_storage(
Expand Down

0 comments on commit 6c7f53b

Please sign in to comment.