Skip to content

Running a load test

loadtest starts many agents at once, each sending your payload to /api/SendPTB on a schedule, and writes one CSV row per request. This page covers running it inside the stack or from the host, the three arrival types, and the knobs that decide how hard it pushes.

You will learn / You need

You will learn: how to run a load test in both ways, what an agent is, how requests are spaced under each arrival type, and where the output lands. You need: a deployed backend (Deploying the stack), a payload (Writing a payload) and a keystore with at least as many funded addresses as agents.

What a run does

loadtest (stealth_name_service/backend/testing_backend/src/bin/loadtest.rs) works like this:

  1. It polls GET /ready on the target host (every 2 seconds, up to 180) until the backend's coin caches are warm. /health would answer too early. If the backend never becomes ready it exits with an error.
  2. It reads ./iota.keystore from its working directory and takes one address per agent: agent i gets the i-th address. It exits with Not enough keys in keystore if there are fewer addresses than --agents.
  3. It loads your payload file as a template. In every string of the template, {{address}} is replaced by the agent's address (inject_address()).
  4. It spawns the agents. They all wait at a barrier, then start together.
  5. For each request an agent fills the auth fields (address, request_number, agent_number, gas_budget), overwriting any that the template has, and POSTs the body.
  6. When every agent is done it writes merged_results.csv and run.json and prints a summary.

So a file you pass as --json is a template: its auth values do not matter, and {{address}} lets a call refer to its own sender:

{"target": "<PACKAGE>::module::register", "type_args": [], "args": [["address", "{{address}}"]]}

Agents, requests and the interval

An agent is one concurrent task with its own sender address and its own HTTP client. Each agent sends --requests requests, so a run sends --agents times --requests in total. The timing diagram shows two agents under the default arrival type with --interval 1:

sequenceDiagram
    participant A0 as Agent 0
    participant A1 as Agent 1
    participant B as Backend
    Note over A0,A1: all agents wait at the barrier
    A0->>B: request 0
    A1->>B: request 0
    Note over A0: next gap = 0 x interval
    Note over A1: next gap = 1/2 x interval
    A0->>B: request 1
    A1->>B: request 1 (staggered)
    Note over A0,A1: from here, one interval between requests
    A0->>B: request 2
    A1->>B: request 2

Every agent sends request 0 at the barrier. The gap after it is stretched by the agent's rank, so the agents drift apart by up to one interval and do not stay in lockstep.

Scheduling is open loop: the next send time is fixed before the request goes out, so a slow response does not delay the next request. What limits an agent is --pipeline-depth, the number of its requests allowed in flight at once (default 1). With depth 1 and a response slower than the gap, the agent falls behind its schedule. The depth must not exceed COINS_PER_REPLICA on the backend.

A request is retried once, after 0.3 seconds, on a network error or a 429, 500, 502, 503 or 504. A request that gets no answer within 55 seconds is recorded as an error.

Arrival types

--arrival-type sets the gap between one request and the next of the same agent.

Type Gap Extra flags Use it for
default The interval. After request 0 only, the interval times agent rank over agent count. none A steady rate of agents / interval requests per second.
staircase The interval divided by the current step, where step 1 is the start and the step grows by one every --increment-interval seconds up to --max-requests-per-interval. --increment-interval, --max-requests-per-interval (both required) A ramp: find where the system saturates. With --max-requests-per-interval 1 it is a flat rate with no stagger, which is what bench_sweep uses for a synchronised burst.
poisson A random gap drawn from an exponential distribution with rate --poisson-lambda per agent per second. --poisson-lambda (required) Independent arrivals at an average total rate of lambda times agents.

Rules the program enforces: --interval above 0; --increment-interval above 0; --max-requests-per-interval at least 1; --poisson-lambda above 0; --pipeline-depth at least 1. An invalid value exits with an error: line before anything is sent.

A rough duration per agent is --requests times --interval seconds, or --requests divided by --poisson-lambda for poisson; loadtest prints this estimate at the start.

Running the load generator

From stealth_name_service/backend, ./deploy.sh benchmark (load only) or ./deploy.sh hybrid (load plus the bridge relayer) starts a loadtest service configured from .env. docker-compose.benchmark.yml substitutes these variables into the command line:

Variable Flag
NUM_AGENTS --agents
LOADTEST_REQUESTS --requests
LOADTEST_INTERVAL --interval
LOADTEST_GAS_BUDGET --gas-budget
LOADTEST_TARGET_URL --target-url
LOADTEST_JSON --json
LOADTEST_ARRIVAL_TYPE --arrival-type
LOADTEST_POISSON_LAMBDA --poisson-lambda
LOADTEST_INCREMENT_INTERVAL --increment-interval
LOADTEST_MAX_REQUESTS_PER_INTERVAL --max-requests-per-interval
LOADTEST_PIPELINE_DEPTH --pipeline-depth

Defaults and sample values: Configuration, Load test. Inside the container the payload path is relative to /app: agent/payloads is mounted at payloads/, so set LOADTEST_JSON=payloads/get_time.json. The keystore is mounted from testing_backend/iota.keystore, and OUTPUT_DIR is /app/output, which is stealth_name_service/backend/shared_data/ on the host. The service does not restart when it finishes.

Run it against a stack deployed in bridge mode (the default, which starts no load generator). This is how bench_sweep and consensus_compare.sh drive it. The working directory must hold iota.keystore:

cd stealth_name_service/backend/testing_backend
cargo run --release --bin loadtest -- --agents 100 --requests 10 --interval 1 \
  --json ../agent/payloads/get_time.json --target-url http://localhost:5000/api/SendPTB

cargo run --release --bin loadtest -- --help lists every flag. Output goes to ./output/ unless OUTPUT_DIR is set. All flags and defaults: Binaries and scripts.

Use a release build for timing runs; bench_sweep stops when it finds only a debug build of loadtest and no release one; --loadtest-bin overrides that.

Fund the agents first

Each agent signs as its own address and pays gas from that address's coins on the network your payload names. An unfunded agent fails every request with No gas coins available for sender <address>. See Fund it.

Output

Each run creates PTB_CALL_<unix timestamp>/ under OUTPUT_DIR with:

File Content
merged_results.csv One row per request (more than one if a response holds several transactions). Column guide: Reading the results.
run.json The run's parameters and its achieved rate against the target. Fields: CSV schemas.

When the run ends, loadtest prints a summary with total, successful and failed requests, the duration, the active window and the throughput. A request counts as successful when its status contains Success.

Bridged requests (for example bridge_request.json) also get a row in events_data/bridge_results.csv from the event handler, with the destination-side timings. See Reading the results.

Check it worked

  • The log shows Backend caches are warm. Starting load test. and ends with a BENCHMARK RESULTS block whose Successful count matches what you expect.
  • merged_results.csv has --agents times --requests data rows and a success column of True.
  • run.json has "rate_achieved": true. false means the generator reached under 90 percent of its target rate, which is a limit of the generator, not a result about the backend.

Next