VUs and load models
Understand concurrency, arrival rates, ramping and scenarios.
On this page
Choose the right working directory. Examples using
npm runshortcuts,node bin/loadstride.js, or top-levelstarter-kit/paths run from the LoadStride source checkout. Those shortcuts do not exist in your application’s package.json. Installed-package users runnpx --no-install loadstridefrom their application directory. See Getting started for both options.
Choose a traffic model
VUs are concurrent users, not users per second. A VU repeatedly executes your default function. If one iteration makes three requests, 100 completed iterations can produce 300 requests. Actual counts depend on your script and failed steps.
For a fixed-user test, choose --vus 10 with either --duration 30s or a total
--iterations 100. For arrival-rate testing, --rate 50 schedules 50 iteration
starts per second, while --max-vus 20 caps concurrent active iterations. It does
not guarantee 50 requests per second. Work that cannot start may be dropped.
There is no universal safe maximum for HTTP VUs. Measure generator CPU, event-loop pressure and target behavior before increasing load. Browser VUs have a separate configurable ceiling (default 20). See browser calibration for measurements and limits; CPU/RAM projections remain unvalidated estimates.
Scheduling and cancellation
Four executors are available:
constant-vus(default): a closed model. Each ofvusworkers starts its next iteration after the previous one finishes. Slower responses lower the achieved iteration rate. Supports a duration or a total iteration count.constant-arrival-rate: an open model. Attemptsrateiteration starts per second independently of iteration completion, forduration. At mostmaxVUsiterations are active. The cap defaults tovus(which defaults to one).ramping-vus: changes the concurrent-user target linearly through configured stages.ramping-arrival-rate: changes iteration starts per second linearly through stages, independently of completion, with a fixedmaxVUscap.
Supplying rate in script options selects arrival mode unless executor is
explicit. An explicit constant-vus with arrival options is a configuration error.
Arrival mode requires an integer rate from 1 to 1,000,000 and a duration; the
validation ceiling is not a throughput guarantee. maxVUs accepts 1 to 100,000.
export const options = {
executor: 'constant-arrival-rate',
rate: 50,
maxVUs: 20,
duration: '10s',
thresholds: { dropped_iterations: ['count==0'] },
};
Slot zero is due at the start. Slots occur every 1000 / rate milliseconds
strictly before the duration deadline, giving ceil(duration_ms * rate / 1000)
planned slots. If no VU is free, the slot is a capacity drop. When the scheduler
is late by one or more complete slots, it counts older slots as scheduler drops
and considers only the latest due slot. It never queues dropped work for replay.
The latest slot can itself be a capacity drop.
Scheduling-delay samples cover dispatched iterations only; missed slots appear in drop counters. Latency metrics do not include dropped iterations or their waiting time, so assess latency alongside drops and achieved throughput. Node timer precision limits high rates; this implementation deliberately avoids busy-waiting.
The JSON scheduler object contains plannedIterations, consideredIterations,
peakVUs, and droppedByReason (capacity, scheduler). For a completed arrival
window, iterations_started.count + dropped_iterations.count equals planned
iterations. On cancellation, future unconsidered slots are not counted as drops.
Arrival runs keep the full duration window and then drain active work; completed
iteration rates therefore need not equal the configured start rate.
Duration-based runs stop starting iterations at the deadline, allow in-flight
work to finish for gracefulStop, then abort built-in HTTP requests and sleeps.
Fixed-iteration runs finish after the total scheduled work completes. Ctrl+C and
SIGTERM abort immediately. Cancellation is cooperative: custom async work must
observe signal, and blocking or never-settling user functions cannot be forcibly
stopped in this single-process engine. Request timeouts default to ten seconds.
Ramp-up stages
Start the demo target if using localhost, then run:
npm run test:ramp
This reads .env.ramp.example (instead of .env) and generates JSON and HTML
reports. It ramps from 0 to 10 VUs over 10 seconds, holds 10 for 10 seconds, then
ramps down to 0 over 10 seconds. Edit the target URL and stages in that file, or
copy it to a separate file and use npm run test:ramp -- --env-file staging.env.
The HTML report includes a chart and table of configured stages.
LOADSTRIDE_EXECUTOR=ramping-vus
LOADSTRIDE_START_VUS=0
LOADSTRIDE_STAGES='[{"duration":"10s","target":10},{"duration":"10s","target":10},{"duration":"10s","target":0}]'
For iteration starts per second, replace these settings with:
LOADSTRIDE_EXECUTOR=ramping-arrival-rate
LOADSTRIDE_START_RATE=0
LOADSTRIDE_MAX_VUS=20
LOADSTRIDE_STAGES='[{"duration":"10s","target":50},{"duration":"10s","target":50},{"duration":"10s","target":0}]'
Remove fixed-mode LOADSTRIDE_RATE, LOADSTRIDE_DURATION, and LOADSTRIDE_ITERATIONS settings when
using stages, and remove LOADSTRIDE_START_VUS when selecting arrival-rate ramps.
Stage durations sum to the scheduling duration; targets are nonnegative integers.
A stage with the same target as the previous stage holds that load. Target zero
can pause load, and a later stage can resume it. The previous target is the next
stage’s starting point. Up to 1,000 stages are accepted.
In user ramps, the linear target is rounded to the nearest integer. New workers are activated on a controller tick (at most once every 20 ms under normal scheduling). Each worker checks the current target before beginning its next iteration. During ramp-down, in-flight iterations finish, so active users may temporarily exceed the reduced target. VU IDs are reused without overlapping iterations for the same ID.
Arrival ramps integrate the piecewise linear rate to derive scheduled starts across
all stages. They use the same no-replay and drop-accounting policy as constant arrivals.
If integrated demand is A iterations, there are ceil(A) planned slots, indexed
from zero; slot zero is due at the onset of the first positive-rate segment. All-zero
profiles schedule no iterations. Zero-rate plateaus schedule no new work. Drops still
occur if generator scheduling or the concurrency cap cannot deliver the target.
CLI --stages accepts the same JSON array; --executor selects its units. For example:
npm run test:ramp -- --stages '[{"duration":"2s","target":5},{"duration":"2s","target":5},{"duration":"2s","target":0}]'
Use stages instead of --duration in ramping mode. --rate or --iterations switches
back to a fixed workload and removes the inherited stages. The report’s stage chart
is the configured plan, not observed history; run metrics remain aggregate.
Multiple scenarios and custom metrics
With the demo server running:
npm run test:scenarios
This reads .env.scenarios.example and runs concurrent browsing, login, and delayed
checkout workloads defined in starter-kit/scenarios.js. JSON and HTML include each
scenario plus an overall result; HTML scenario panels can be expanded for their
metrics, stages, custom metrics, checks, and thresholds.
Each scenario chooses an exported function with exec. Its workload uses any of the
four existing executors. startTime delays its start relative to the load phase
(default zero). A default function is optional when every scenario specifies a
named function. Programmatic callers can also pass a function as exec.
export const options = {
customMetrics: {
checkout_failures: 'counter',
checkout_success: 'rate',
checkout_time: 'trend',
},
thresholds: { checkout_failures: ['count==0'] }, // Overall thresholds.
scenarios: {
browsing: { exec: 'browse', rate: 50, maxVUs: 20, duration: '30s' },
checkout: {
exec: 'checkout', vus: 5, iterations: 100, startTime: '2s',
thresholds: { checkout_success: ['rate==1'], checkout_time: ['p(99)<500'] },
},
},
};
export async function browse({ http }) {
await http.get(process.env.TARGET_URL);
}
export async function checkout({ http, metrics, scenario, vu, iteration, data }) {
const response = await http.get(process.env.TARGET_URL);
let success = false;
try { success = !response.error && response.status === 200 && response.json().ok === true; } catch {}
metrics.checkout_success.add(success);
metrics.checkout_failures.add(success ? 0 : 1);
metrics.checkout_time.add(response.duration);
}
Top-level thresholds evaluate the merged result. Thresholds inside a scenario
apply only to that scenario. Any scenario interruption, iteration error, or failing
scenario/overall threshold fails the run. Other scenarios continue through a local
failure; a scenario’s expired graceful stop cancels its own work. External cancellation
stops active work and prevents delayed scenarios from starting. All scenario
configuration and execution functions are validated before setup or traffic.
setup and teardown execute once for the whole test. Setup data is shared by all
scenarios, and hook requests stay outside measured load. Iteration context includes
scenario (its name) and scoped metrics. VU IDs and iteration indices are local to
each scenario; use (scenario, vu) when identifying a user. All scenarios still
share one process, module state, and fetch connection pooling.
Common timeout, gracefulStop, and customMetrics may be declared at the top level.
Scenario values override these defaults. Global workload settings (rate, vus,
duration, etc.) are rejected when using scenarios; declare them inside each
scenario instead. The dedicated env file avoids the single-workload .env defaults.
Use --url to override its target, and optionally LOADSTRIDE_SCENARIOS containing a JSON
object to replace the scenario map. Function names in that JSON must match script
exports. Per-scenario customMetrics can add definitions; a shared name must have
the same type in every scenario. Limits: 50 scenarios and 100 distinct custom metrics.
| Custom type | Recording API | Summary and threshold fields |
|---|---|---|
counter |
.add(nonnegativeSafeInteger) |
count (sum), rate (sum per second) |
rate |
.add(boolean) |
count, passed, failed, rate (fraction true) |
trend |
.add(nonnegativeMilliseconds) |
min, avg, max, p(50), p(95), p(99) |
Names must begin with a lowercase letter and contain lowercase letters, digits, or
underscores, up to 64 characters. Built-in metric names are reserved. Record through
metrics.<name>.add(value); invalid values throw an iteration error. Trend values
use bounded histograms with nanosecond quantization and support values up to
Number.MAX_SAFE_INTEGER / 1e6 milliseconds. Rate/trend thresholds fail without
observations; a counter threshold can pass at zero. Custom metrics also work in
ordinary single-workload scripts.
Aggregate latency and trend percentiles use merged histograms, not averages of scenario percentiles. Aggregate counter/throughput rates use total elapsed load time, including delays and drain; scenario rates use their own elapsed load time. Boolean rates pool observations. Overall peak VUs is measured concurrently, not the sum of per-scenario peaks. Generator diagnostics describe the shared process, so scenario measurement intervals can include work from other scenarios.
Live progress summarizes overall counts and active scenarios. Programmatic progress
snapshots also include a scenarios array with each workload’s status and counters.
When iteration-based scenarios are present, aggregate percentage averages scenario
progress because no fixed total duration is known. JSON scenario result startTime
is in seconds; normalized options use milliseconds like other engine durations.
Based on the released v0.2.0 guide. View source on GitHub.