Skip to content

perf(generate): refresh gas weights without pausing generation - #357

Merged
onbjerg merged 2 commits into
mainfrom
pyramid/188cae74-ef19-4d71-8d54-4a8092908d2d
Nov 9, 2026
Merged

onbjerg merged 2 commits into
mainfrom
pyramid/188cae74-ef19-4d71-8d54-4a8092908d2d

Conversation

@onbjerg

@onbjerg onbjerg commented Nov 5, 2026

Copy link
Copy Markdown
Member

With --gas-weighted-mix, generate re-sampled gas every 10 s by sending one blocking eth_simulateV1 per mix item, one after another, inside the generation loop. With a 27-item mix, each refresh took about 8.5 s, so bench send had nothing to send for most of every 10 s. tempo bench-e2e run 41826454576 hit 622 TPS in bursts but averaged 324.

The first sample still blocks, so the mix is set before any workload is emitted. Later refreshes build their calls on the loop, which is cheap, then run the RPCs on the tokio runtime. Their weights apply once every call has returned, matched by item, because the selector may prune entries in the meantime. A failed refresh still aborts generation.

@onbjerg
onbjerg marked this pull request as ready for review November 9, 2026 14:30

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Comment on lines +1760 to +1766
if gas_refresh.as_ref().is_some_and(|refresh| refresh.is_finished()) {
let refresh = gas_refresh.take().expect("finished refresh exists");
// A failed refresh keeps the weights in use; only the first sample must succeed.
match runtime.block_on(refresh).wrap_err("gas sampling task failed").and_then(|r| r) {
Ok(estimates) => selector.set_sampled_gas_estimates(&estimates)?,
Err(error) => eprintln!("gas sampling refresh failed; keeping weights: {error:#}"),
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 (optional) Operators now get generation that keeps running when a later gas sample shows a mix item reverting or the RPC failing. The base aborted in that case, and the PR description says it still does. The Err(error) => eprintln!(...) arm at generate.rs:1765 drops every refresh error, including simulation_gas's "gas sample call {index} failed" revert check. Fix: either propagate refresh errors as the base did, or keep the log-and-continue path for transport/RPC errors only and still abort on a failed or reverting sample call. If you keep the current behaviour, correct the PR description.

Why this was flagged

Trigger: generate runs with --gas-weighted-mix and a gas sampling RPC. After the first sample, a workload item starts reverting, for example because a sender's token balance or allowance runs out, or the sampling RPC goes away. simulate_gas_samples returns an Err, either from simulation_gas ("gas sample call {index} failed", generate.rs:2272) or from the request. The loop at generate.rs:1763-1766 logs it with eprintln! and carries on with stale weights. It retries every GAS_SAMPLE_INTERVAL and fails the same way each time, so the run finishes and writes a workload of transactions that revert on chain. On the base, refresh_gas_estimates(...)? inside the loop returned the error and stopped generation, which acted as a periodic liveness check on the workload. The PR description says "A failed refresh still aborts generation". The code comment at 1762 says the opposite, so the description and the code disagree.

Verification: Trigger: a run with --gas-weighted-mix and a gas sampling RPC, where a later refresh fails after the first sample succeeded. In the base, refresh_gas_estimates(...)? was called inside the loop, so any refresh error ended generate_txs with an error. Every refresh error is swallowed at generate.rs:1763-1766, revert-status failures included.

Comment on lines +1768 to 1774
if let Some(client) = &gas_client &&
gas_refresh.is_none() &&
last_gas_sample.elapsed() >= gas_sample_interval
{
refresh_gas_estimates(adapter, spec, setup_bindings, ctx, &mut selector, provider)?;
let samples = gas_samples(adapter, spec, setup_bindings, ctx, &selector)?;
gas_refresh = Some(runtime.spawn(simulate_gas_samples(client.clone(), samples)));
last_gas_sample = Instant::now();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 (optional) Operators benchmarking a node with --gas-weighted-mix now get near-continuous eth_simulateV1 traffic to that node. The base left about 10 s idle between refreshes. last_gas_sample is reset when a refresh is spawned, not when it finishes. So a refresh lasting close to gas_sample_interval is followed at once by the next. Fix: measure the interval from the moment the refresh result is collected, by setting last_gas_sample = Instant::now() where the finished handle is taken at 1761. Keep the first-sample reset at 1743.

Why this was flagged

generate runs with --gas-weighted-mix. gas_sample_rpc is args.rpc (generate.rs:162), the node under benchmark. Each refresh sends one eth_simulateV1 per mix item in sequence (simulate_gas_samples), which the PR puts at about 8.5 s for 27 items. At generate.rs:1773-1774 the refresh is spawned and last_gas_sample is reset straight away. The next refresh is gated only by gas_refresh.is_none() and elapsed() >= gas_sample_interval (1769-1770), so it starts 10 s after the previous one started. With D = 8.5 s the duty cycle is 85%. On the base, last_gas_sample = Instant::now() ran after the blocking refresh_gas_estimates returned, giving at least 10 s without simulate load (duty D/(D+10), about 46%). No cap or backoff bounds how often refreshes are sent, so the node under benchmark serves extra simulation load that skews its measurements.

Verification: In HEAD, line 1773 spawns simulate_gas_samples and line 1774 resets last_gas_sample = Instant::now() straight away, so the interval now runs from start to start. With 8.5 s refreshes, the duty cycle of eth_simulateV1 traffic rises from about 8.5/18.5 (46%) to about 8.5/10 (85%), and to 100% if a refresh takes 10 s or more. The target is args.rpc (line 162), the node under benchmark.

@onbjerg
onbjerg merged commit a255d3e into main Nov 9, 2026
11 checks passed
@onbjerg
onbjerg deleted the pyramid/188cae74-ef19-4d71-8d54-4a8092908d2d branch November 9, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant