Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit a5c6264

Browse files
liamaharongpestana
authored andcommitted
try-runtime-cli: improve ci stability (#14030)
* 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
1 parent 3b05747 commit a5c6264

File tree

1 file changed

+24
-7
lines changed
  • utils/frame/remote-externalities/src

1 file changed

+24
-7
lines changed

utils/frame/remote-externalities/src/lib.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use sp_core::{
4040
pub use sp_io::TestExternalities;
4141
use sp_runtime::{traits::Block as BlockT, StateVersion};
4242
use std::{
43-
cmp::max,
43+
cmp::{max, min},
4444
fs,
4545
num::NonZeroUsize,
4646
ops::{Deref, DerefMut},
@@ -157,10 +157,14 @@ impl Transport {
157157
} else {
158158
uri.clone()
159159
};
160-
let http_client = HttpClientBuilder::default().build(uri).map_err(|e| {
161-
log::error!(target: LOG_TARGET, "error: {:?}", e);
162-
"failed to build http client"
163-
})?;
160+
let http_client = HttpClientBuilder::default()
161+
.max_request_body_size(u32::MAX)
162+
.request_timeout(std::time::Duration::from_secs(60 * 5))
163+
.build(uri)
164+
.map_err(|e| {
165+
log::error!(target: LOG_TARGET, "error: {:?}", e);
166+
"failed to build http client"
167+
})?;
164168

165169
*self = Self::RemoteClient(Arc::new(http_client))
166170
}
@@ -323,16 +327,29 @@ where
323327
B::Hash: DeserializeOwned,
324328
B::Header: DeserializeOwned,
325329
{
330+
const DEFAULT_PARALLELISM: usize = 4;
326331
const BATCH_SIZE_INCREASE_FACTOR: f32 = 1.10;
327332
const BATCH_SIZE_DECREASE_FACTOR: f32 = 0.50;
328333
const INITIAL_BATCH_SIZE: usize = 5000;
329334
// NOTE: increasing this value does not seem to impact speed all that much.
330335
const DEFAULT_KEY_DOWNLOAD_PAGE: u32 = 1000;
331336

332337
/// Get the number of threads to use.
338+
/// Cap the number of threads. Performance improvement beyond a small number of threads is
339+
/// negligible, and too many threads can create issues with the HttpClient.
333340
fn threads() -> NonZeroUsize {
334-
thread::available_parallelism()
335-
.unwrap_or(NonZeroUsize::new(1usize).expect("4 is non-zero; qed"))
341+
let avaliable = thread::available_parallelism()
342+
.unwrap_or(NonZeroUsize::new(1usize).expect("1 is non-zero; qed"))
343+
.get();
344+
assert!(avaliable > 0, "avaliable parallelism must be greater than 0");
345+
346+
let requested: usize = match std::env::var("TRY_RUNTIME_MAX_THREADS") {
347+
Ok(n) => n.parse::<usize>().expect("TRY_RUNTIME_MAX_THREADS must be a number"),
348+
Err(_) => Self::DEFAULT_PARALLELISM,
349+
};
350+
assert!(requested > 0, "TRY_RUNTIME_MAX_THREADS must be greater than 0");
351+
return NonZeroUsize::new(min(requested, avaliable))
352+
.expect("requested and avaliable are non-zero; qed")
336353
}
337354

338355
async fn rpc_get_storage(

0 commit comments

Comments
 (0)