You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some instances, it would be useful to have a ThrottleLayer to not flood the node with requests all at once. While the RetryLayer works perfectly for retrying requests that exceed RPC provider limits, the ThrottleLayer could throttle outbound requests before they are sent.
The following snippet shows an example that fetches 100k blocks concurrently. In this example a ThrottleLayer would be helpful to limit n requests per second.
#[tokio::main]asyncfnmain() -> eyre::Result<()>{// --snip--// Init the providerlet client = ClientBuilder::default().layer(RetryBackoffLayer::new(10,300,330)).http(rpc_endpoint.parse()?);let provider = ProviderBuilder::new().on_client(client);let futures_unordered = FuturesUnordered::new();// Get 100_000 blockslet block_number = provider.get_block_number().await?;for i in block_number - 100_000..block_number {let provider = provider.clone();
futures_unordered.push(asyncmove{
provider
.get_block(i.into(),BlockTransactionsKind::Hashes).await});}// Await the resultslet res = futures_unordered.collect::<Vec<_>>().await;Ok(())}
Component
rpc, transports
Describe the feature you would like
In some instances, it would be useful to have a
ThrottleLayer
to not flood the node with requests all at once. While theRetryLayer
works perfectly for retrying requests that exceed RPC provider limits, theThrottleLayer
could throttle outbound requests before they are sent.The following snippet shows an example that fetches 100k blocks concurrently. In this example a
ThrottleLayer
would be helpful to limitn
requests per second.We currently have a working version of a ThrottleLayer built and I would be happy to open a draft PR with this if you think it would be useful to add to
alloy
.Additional context
No response
The text was updated successfully, but these errors were encountered: