Skip to main content

Load Testing Configuration

TestFly provides a centralized loadtest: configuration block in testfly.yml. This allows teams to define global sensible defaults for performance runs across local and CI environments.


1. The loadtest: Block​

Add the optional loadtest: section to your testfly.yml:

loadtest:
enabled: false # reserved flag; explicit runner calls are not currently gated
baseUrl: https://api.example.com
engine: auto # auto (prefers Gatling if present, else JDK) | gatling | jdk
users: 10 # virtual users started over rampUp (not a concurrency target)
rampUp: 10s # window over which the users start evenly (e.g. 10s, 1m)
hold: 30s # how long each user loops, counted from its own start (e.g. 30s, 5m)
cooldown: 5s # accepted but not applied by any engine yet (logs a WARN)
maxUsers: 1000 # safety ceiling: users is clamped; workloads above it are rejected
resultsDir: target/loadtest # one run directory per run (metrics, reports, result file)
reportEnabled: true # generate standalone HTML load test report
requestTimeoutSeconds: 30 # per-request timeout in seconds (both engines)
retention: # run directories in resultsDir, swept after every run (both engines)
runs: 10 # keep the newest 10 of the scenario that just ran; 0 = keep all (default)
maxAgeDays: 14 # delete TestFly run directories older than 14 days; 0 = no limit (default)
gatling: # the forked Gatling child JVM (Gatling engine only)
maxHeap: 1g # -Xmx1g; "50%" gives -XX:MaxRAMPercentage=50; unset = JVM default (default)
jvmArgs: # one JVM option per element, checked against an allowlist when a run starts
- "-XX:+UseG1GC"
- "-XX:+HeapDumpOnOutOfMemoryError"
maxParallelRuns: 2 # Gatling runs at once in this JVM, 1..16; 1 = one at a time (default)
proxy: # HTTP proxy for load and OAuth2 token requests (both engines); unset = see below
host: proxy.corp.example
port: 3128
username: ${LOAD_PROXY_USER}
password: ${LOAD_PROXY_PASSWORD}
nonProxyHosts: [localhost, "*.internal.example"]
tls: # trust and client stores (both engines); unset = each engine's default
trustStore: { path: certs/load-trust.p12, password: ${LOAD_TRUSTSTORE_PASSWORD} } # type: PKCS12 (default) | JKS
keyStore: { path: certs/load-client.p12, password: ${LOAD_KEYSTORE_PASSWORD} } # mTLS
insecureTrustAll: false # trust any server certificate (hostname still verified)

The proxy and tls blocks are new in 1.1.0; see Authentication, Proxy and TLS. They are read from testfly.yml only, like retention and gatling, and LoadTestConfig exposes them through getProxy() and getTls().

The retention and gatling blocks are new in 1.1.0. They are host resources, so they are read from testfly.yml only: @LoadTest and LoadScenario have no setting for them. In a simulation, the values come from the first scenario's configuration, as resultsDir does. In code, LoadTestConfig exposes the resolved values through getRetentionRuns(), getRetentionMaxAgeDays(), getGatlingMaxHeap(), getGatlingJvmArgs() and getGatlingMaxParallelRuns().


2. Configuration Reference​

PropertyTypeDefaultDescription
enabledbooleanfalseReserved effective flag (overridable via features.loadtest); the current LoadTestRunner.run() path does not enforce it.
baseUrlstringnullTarget URL after scenario/annotation overrides. Gatling falls back to execution.baseUrl; the JDK engine requires this value or a scenario/annotation URL.
enginestringautoExecution engine: auto (prefers Gatling if present, falls back to JDK), gatling (strictly Gatling), or jdk (native virtual threads).
usersint10Number of virtual users started evenly over rampUp if not specified in code. Each one runs the scenario in a loop for hold. This is not a concurrency target: peak concurrency equals users only when rampUp <= hold.
rampUpstring10sWindow over which the virtual users start, evenly spaced (e.g. 10s, 1m).
holdstring30sHow long each virtual user loops over the scenario, counted from its own start (e.g. 30s, 5m). A run takes about rampUp + hold.
cooldownstring5sAccepted for compatibility but not applied by either engine. When it is greater than zero, one WARN is logged per JVM.
maxUsersint1000Safety ceiling. The resolved users value is clamped to it. A workload whose peak exceeds it is rejected before any request: the peak concurrency of a closed workload, or the peak arrival rate and user-count steps of an open one. A simulation checks the combined peaks.
resultsDirstringtarget/loadtestParent directory of the run directories. Every run, on both engines, creates <resultsDir>/<scenario-or-simulation>-<millis>/ with its result file testfly-loadtest-result.json; see Reporting. Old run directories are kept unless retention is set.
reportEnabledbooleantrueGenerates standalone HTML load test report and correlates native Gatling interactive reports.
requestTimeoutSecondsint30Per-request timeout in seconds, applied by both engines (JDK: connect and request timeout; Gatling: requestTimeout). A timed-out request is a failed request with status -1.
retention.runsint0Run directories kept per scenario (for a simulation, per simulation name), newest first. 0 keeps all. Range 0 and up; a negative value logs a WARN and becomes 0. See Run retention.
retention.maxAgeDaysint0Maximum age in days of any TestFly run directory in resultsDir, whatever its scenario. 0 is no limit. Range 0 and up; a negative value logs a WARN and becomes 0.
gatling.maxHeapstringunsetMaximum heap of the Gatling child JVM: <n>k, <n>m or <n>g (at least 64m) gives -Xmx<n>k/m/g; <n>% (above 0, at most 100) gives -XX:MaxRAMPercentage=<n>. Unset or blank adds no flag, so the JVM default applies (25% of the physical or container RAM). Checked when a Gatling run starts. See Gatling child JVM.
gatling.jvmArgslistemptyExtra options for the Gatling child JVM, one option per element, each checked against an allowlist when a Gatling run starts.
gatling.maxParallelRunsint1Gatling runs that execute at the same time in this JVM. 1 runs them one at a time, as before 1.1.0. Range 1 to 16: a lower value becomes 1 and a higher one 16, each with a WARN. See Parallel Gatling runs.
proxy.host, proxy.portstring, intunsetHTTP proxy for load requests and OAuth2 token requests on both engines. When set, the JVM proxy properties are ignored. Unset: the JDK engine uses the JVM proxy properties and TestFly sets no proxy on Gatling. See Proxy.
proxy.username, proxy.passwordstringunsetProxy credentials, both or neither, sent only to the proxy. Use ${ENV} placeholders.
proxy.nonProxyHostslistemptyHosts reached directly; * wildcards.
tls.trustStorepath, type, passwordunsetTrust store (PKCS12 by default, or JKS) that replaces the default trust. See TLS.
tls.keyStorepath, type, passwordunsetClient key store for mTLS; the key password must equal the store password. Without a trustStore, the JVM default trust applies.
tls.insecureTrustAllbooleanfalseTrusts any server certificate but still verifies the hostname; logs a WARN; conflicts with trustStore. Without any tls setting, Gatling trusts every certificate with no hostname check (Gatling's default).
Workload model

users, rampUp and hold describe an open workload: users arrive evenly over rampUp and each one loops for hold from its own start. With users: 10, rampUp: 6s and hold: 2s, early users finish before late ones start, so fewer than 10 run at the same time. cooldown has no effect. The decision is recorded in docs/adr/0003-load-test-workload-model.md (ADR 0003) in the repository.

For constant concurrency, arrival rates, spikes or a ramp-down, set an explicit workload in code with LoadScenario.workload(...) (Gatling engine only). It is configured in code only: a scenario with a workload ignores users, rampUp, hold and cooldown from this block and from @LoadTest. See Workload models.

Duration values and rounding​

The engines apply rampUp, hold and cooldown in whole seconds. The same rule applies wherever the value is set: LoadScenario.rampUp/hold/cooldown(Duration) in code, the @LoadTest strings, and loadtest.rampUp, loadtest.hold and loadtest.cooldown in testfly.yml.

  • Format (strings). A number with the unit ms, s, m or h (in any case), or a plain number of seconds. Decimals are allowed: 30s, 1.5s, 800ms, 0.5m, 2h, 2.5.
  • Rounding. A positive fraction of a second rounds up: 800ms → 1 s, 1500ms → 2 s, 1.5s → 2 s, 0.5m → 30 s, 2.5 → 3 s, and Duration.ofMillis(800) → 1 s. Whole values and zero are unchanged.
  • Missing or blank values use the default: rampUp 10 s, hold 30 s, cooldown 5 s.
  • Invalid or negative values, such as fast or -5s, log a WARN that names the key and the value, and the default is used. A negative Duration passed to LoadScenario.rampUp/hold/cooldown throws IllegalArgumentException.
Changed in 1.1.0

Durations used to be truncated, so a hold under one second (hold(Duration.ofMillis(800)) or hold: 800ms) became 0 s and the run sent no request. A decimal string such as 1.5s was not understood and silently fell back to the default. Both now follow the rules above.


3. Run Retention​

Every run creates a run directory <resultsDir>/<name>-<millis>/. By default TestFly keeps all of them. Set loadtest.retention to delete old ones automatically. The design is recorded in docs/adr/0007-load-test-resources-retention-parallel-runs.md (ADR 0007) in the repository.

loadtest:
resultsDir: target/loadtest
retention:
runs: 10 # per scenario: keep the newest 10 run directories
maxAgeDays: 14 # all scenarios: delete run directories older than 14 days

What retention can delete​

Only a TestFly run directory, which is a direct child of resultsDir that meets all of these conditions:

  • Its name is <name>-<13-digit millis>, where <name> contains only letters, digits, _ and -.
  • It is a real directory, not a symbolic link.
  • It contains the empty marker file .testfly-run, which TestFly writes into every run directory it creates from 1.1.0. A run directory written before 1.1.0 has no marker, so it qualifies instead through a TestFly file: testfly-metrics.json, testfly-loadtest-result*.json or gatling-subprocess.log.

What retention never deletes​

  • Anything else under resultsDir, such as your own folders and files. This includes a folder whose name matches the pattern, such as backup-1700000000000, when it has no marker and no TestFly file.
  • Symbolic links, and the targets they point to. A link inside a deleted run directory is deleted as a link; its target is not touched. If resultsDir itself is a link, it is resolved once and its target is swept.
  • The directory of the run that just finished.
  • A run in progress. A run holds an exclusive lock on its .testfly-run marker until it is over, and a directory whose marker is locked, by this JVM or another one, is kept. A Gatling run holds the lock for the whole run; a JDK run, which creates its directory at the end, holds it while it writes the result file.
  • A directory less than 60 s old, judged by the millis in its name. This covers the moment between creating a directory and locking its marker.

If the file system cannot create or lock the marker (for example NFS without a lock daemon, some VM shared folders, or any other I/O error), the run is not failed: TestFly logs one WARN per JVM and the run goes on without the cross-process lock. Retention in the same JVM still protects the run, and the 60 s guard still applies, but another JVM or host sharing resultsDir no longer sees the run as in progress.

A protected directory beyond the limits is kept and is considered again by later sweeps.

Limits​

  • runs counts per scenario. It keeps the newest runs directories of the scenario that just ran, newest first by the millis in the name. Directories of other scenarios are not counted and not deleted by this rule, so a busy scenario never pushes out another one's history. For a simulation, the count is per simulation name. Scenarios whose names give the same directory name (for example a b and a_b, both a_b) share one count. A run in progress counts towards runs.
  • maxAgeDays applies to every TestFly run directory in resultsDir, whatever its scenario, so it also clears the directories of renamed or deleted scenarios. The age is the millis in the name, never the modification time: copying a directory or touching a file does not change its age.
  • With both set, the newest runs directories of the scenario that just ran are exempt from the age rule. They are kept even when they are older than maxAgeDays.
  • With both at 0 (the default), nothing is deleted and no sweep runs.

When the sweep runs​

Once after every run:

  • JDK engine: after every run, whether it passed, was cancelled, was aborted, timed out or failed validation. A run that returns metrics sweeps right after its result file is written.
  • Gatling engine: after every run that got as far as its run directory, whether it passed, failed or was cancelled while running, once the run is over: its results are written, its run directory is unlocked and its run slot is released. Two kinds of Gatling run sweep nothing: a run cancelled while it was still queued for a run slot, and a run rejected by the maxHeap / jvmArgs check (see below).

A directory is first renamed to .<name>.deleting-<uuid> and then deleted, so two sweeps never delete the same tree. If a deletion is interrupted, a later sweep removes the leftover. A sweep never fails a test: a problem only logs a WARN. When something was deleted, an INFO line names the number of directories and the limits.

Shared or network disks

The run lock is a FileLock, which is advisory on Linux and macOS and not reliable on NFS and other network filesystems. Where it cannot be taken at all, runs no longer fail: they go on with one WARN per JVM, but without the cross-process lock. Either way, when several hosts or JVMs write to one shared resultsDir, a sweep on one of them can delete a run that is still in progress on another. Use one resultsDir per host there, or no runs limit (runs: 0). The same applies when a TestFly version older than 1.1.0 writes to the same resultsDir at the same time: its run directories have no marker and are not locked.

Where the file system cannot lock files at all, retention keeps every run directory that has a .testfly-run marker: those are never deleted there. Run directories without a marker, such as those written before 1.1.0, can still be deleted through the legacy-file rule, with no cross-host protection. On such file systems, use one resultsDir per host and delete old runs yourself.


4. Gatling Child JVM​

Each Gatling run executes in a forked child JVM (see Gatling Run Lifecycle). loadtest.gatling sets the child's resources. These keys have no effect on the JDK engine, which runs inside the test JVM.

maxHeap​

ValueChild JVM option
unset or blank (default)none: the JVM default applies, 25% of the physical or container RAM
<n>k, <n>m, <n>g (whole number, unit in any case), such as 512m or 1g-Xmx followed by the value, such as -Xmx1g; at least 64m
<n>%, above 0 and at most 100, such as 50% or 12.5%-XX:MaxRAMPercentage=<n>

A unit is required: a bare 1024 is rejected, because the JVM would read it as bytes.

jvmArgs​

Each element is exactly one JVM option. TestFly starts the child without a shell, so an element is never split at spaces. Allowed forms:

  • -Xms<size>, -Xmx<size>, -Xss<size>, -Xmn<size>
  • -XX:<option>, except the four listed below
  • -D<key> and -D<key>=<value>, except the reserved keys listed below
  • -ea[:<package>], -da[:<package>], -esa, -dsa and their long forms such as -enableassertions
  • -verbose:gc, -Xlog:<...>
  • --add-opens=<value>, --add-exports=<value>, --enable-native-access=<value>, --enable-preview

Everything else is rejected, including:

RejectedReason
-javaagent:, -agentlib:, -agentpath:Agents run arbitrary code in the child. Use JAVA_TOOL_OPTIONS for a profiler agent (see below).
-cp, -classpath, --class-path, -jar, -p, --module-pathTestFly sets the child's class path.
@<file> (argument files), -XX:Flags=…, -XX:VMOptionsFile=…They read options from a file and would bypass the allowlist.
-XX:OnError=…, -XX:OnOutOfMemoryError=…They run a command.
-Dtestfly.<…>testfly.* properties are reserved for TestFly.
-Dgatling.data.enableAnalytics, -Dgatling.charting.indicators.percentile1 to percentile4TestFly pins them (no usage analytics; p50/p75/p95/p99 in Gatling's report).
-Dgatling.ssl.*, -Dgatling.http.enableHostnameVerificationTestFly sets them from loadtest.tls inside the child, never on the command line, which other users can read.
a zero size: -Xmx0, -Xms0, -Xss0k, -Xmn0m, …A size must be greater than 0.
--add-opens <value> and the other two-element formsUse the one-element form --add-opens=<value>.
a blank element, an element with leading or trailing spaces, an element that does not start with -An element must be one option.

Conflict rule. When maxHeap is set, -Xmx…, -XX:MaxHeapSize, -XX:MaxRAMPercentage, -XX:MaxRAM, -XX:MaxRAMFraction, -XX:MinRAMPercentage and -XX:InitialRAMPercentage in jvmArgs are rejected, so the heap is set in one place. -Xms… is allowed.

Placeholders. ${VAR} and ${VAR:-default} placeholders work in maxHeap and in each jvmArgs element, as in other configuration values, for example maxHeap: "${GATLING_HEAP:-1g}". They are resolved when the configuration loads, before the check.

When the values are checked. The YAML values are stored as given, so a bad value never breaks configuration loading. They are checked when a Gatling run starts, before it waits for a run slot, creates a run directory or sends a request. A bad value fails that run with IllegalArgumentException, for example [LoadTest] loadtest.gatling.jvmArgs[0] '-javaagent:/x.jar' is not allowed: agents are not allowed (use JAVA_TOOL_OPTIONS for a profiler agent). Allowed: ….

Order on the command line. java, then jvmArgs in order, then the maxHeap option, then TestFly's own options (--add-opens java.base/java.lang=ALL-UNNAMED, the run configuration, the pinned gatling.* properties and -cp). TestFly's options come last, so they win.

JAVA_TOOL_OPTIONS and JDK_JAVA_OPTIONS​

The child inherits the test JVM's environment, so these variables reach the child unchanged. TestFly does not check them against the allowlist; they remain the way to add an agent, for example a corporate certificate or proxy agent or a profiler. The JVM applies them before the command-line options, so maxHeap and jvmArgs win when both set the same option. The test JVM's own options, such as a Surefire argLine with a coverage agent, are not passed to the child.

Checking the effective heap​

The child prints one line to gatling-subprocess.log in the run directory when the simulation starts:

[TestFly] Gatling child JVM: maxMemory=<bytes> availableProcessors=<n>

maxMemory is Runtime.maxMemory(), the heap the child can use. It is usually a little below the -Xmx value.

Class path​

The child JVM still gets the test JVM's full class path. A minimal class path is not a goal for 1.1.0: it would drop your gatling.conf, logback-test.xml and optional libraries such as the JMESPath runtime and Jackson modules. Classes are loaded only when used, so unused JARs cost almost no heap; bound the child's memory with maxHeap. The decision is recorded in docs/adr/0007-load-test-resources-retention-parallel-runs.md (ADR 0007) in the repository.


5. Environment Profiles & CI Overrides​

TestFly profiles allow you to define lightweight parameters for local smoke testing while executing high-concurrency benchmarks in CI pipelines:

testfly.yml (Local Default)​

loadtest:
engine: auto
users: 5
rampUp: 2s
hold: 5s

testfly-performance.yml (CI Staging / Benchmark Profile)​

loadtest:
engine: gatling
users: 250
rampUp: 30s
hold: 120s
cooldown: 10s
reportEnabled: true

Activate the profile with Maven:

mvn test -Dtestfly.profile=performance

6. Feature Switchboard Integration​

Under TestFly's master switchboard, load testing can also be toggled globally across all suites:

features:
loadtest: false # Completely disables load test execution across all suites