Execution Engines (Gatling vs. JDK)
TestFly is engine-agnostic. It features a dual-engine architecture designed to deliver maximum flexibility: an ultra-high performance Gatling engine for enterprise load simulations, and a zero-dependency JDK engine for lightweight local smoke tests.
1. Engine Comparison
| Feature | Gatling Engine (gatling) | JDK Engine (jdk) |
|---|---|---|
| Underlying Tech | Gatling 3.16.0 + Netty async IO | Java 21+ HttpClient + Virtual Threads |
| Classpath Dependency | Optional (gatling-charts-highcharts) | Built into Java standard library |
| Process Isolation | Dedicated forked JVM subprocess | Runs in-process on test worker thread |
| Native Report | Interactive Highcharts HTML report | Integrated TestFly HTML dashboard |
| Subprocess Log | gatling-subprocess.log | Standard TestFly logs |
| Metrics Source | TestFly's own sidecar testfly-metrics.json (counts, status codes, millisecond latency histogram) | Measured in-process |
| Latency Percentiles | p50, p75, p90, p95, p99 (exact, linear interpolation) | p50, p75, p90, p95, p99 (exact, linear interpolation) |
| Latency Population | Requests that received an HTTP response | Also includes the elapsed time of connection failures and timeouts |
| HTTP Status Codes | Real status per response | Real status per response |
| JSONPath in checks | Full Gatling JSONPath (a path without $ is read as $.path) | $.a.b, $.a[0].b, $[0] only (same $.path rule) |
Response header checks and extractions (responseHeader(..)) | Yes, Gatling's header check: the first value, name in any case | Yes, same rules |
Regex checks and extractions (regex(..)) | Yes, evaluated in the child JVM by TestFly's own extractor, not Gatling's regex check, so group rules and defaults are those of the JDK engine | Yes |
XPath checks and extractions (xpath(..)) | XPath 1.0, evaluated in the child JVM by TestFly's own JDK XPath extractor, not Gatling's Saxon-based xpath check; same XXE protection | XPath 1.0 (javax.xml.xpath), DOCTYPE rejected |
JMESPath checks and extractions (jmesPath(..)) | Full JMESPath: Gatling's jmesPath check, or, for an extraction with a default, TestFly's evaluation with the same library; validated before the run when io.burt:jmespath-jackson (a Gatling dependency) is on the classpath | Subset a.b, a[0].b, "key", [0]; anything else is rejected before any request |
Extraction defaults (extract(var, source, default)) | Yes, the request stays OK; a body that is not JSON takes the default for jmesPath and for a jsonPath of the JDK subset, but is KO for a jsonPath outside it (Gatling's withDefault) | Yes; a body that is not JSON takes the default |
| HTTP methods | GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS | Same |
Default body Content-Type | Inferred from the declared body (JSON, XML or text); a user-set header wins | Same rule |
users / rampUp / hold | Yes (whole seconds) | Yes (whole seconds) |
Workload models (workload(...)) | Yes | No: rejected before any request |
Simulations (loadSimulation(...)) | Yes | No: rejected before any request |
Flow control (repeat, doIf, doIfOrElse, randomSwitch, group, tryMax, pace) | Yes; a group also appears in Gatling's report | Yes, same semantics and metrics; a group only changes step names |
Steps that never ran (an untaken branch, a step skipped in a tryMax) | In the metrics with 0 requests and NaN p95/p99 | Same |
SLAs (sla(...)) | Yes, evaluated by TestFly; also shown as native assertions in Gatling's report | Yes, evaluated by TestFly |
Baselines and testfly-loadtest-result.json | Yes | Yes |
Feeder strategies (queue, circular, randomOrder, shuffle) and several feeders | Yes, polled through TestFly's own cursor at the start of each iteration, not Gatling's feed(..) | Yes, same semantics |
Feeder exhaustion (queue, shuffle) | The user exits (exitHereIf); feederExhausted() is set, the run is not partial. A closed workload keeps replacing users (each waits 100 ms and exits) until its injection step ends | The user ends; same flag and WARN |
| CSV parsing | Same RFC 4180 parser; above 100,000 records the child JVM reads the file again and checks its size and modification time | Parsed once in the test JVM |
| Custom feeders | Its own describe() when overridden; otherwise sampled to at most 5000 records, which the users cycle (WARN when cut) | next() called live per iteration; the last record is reused when it has no more |
Authentication (LoadAuth: Basic, Bearer, OAuth2 client credentials, fromConfig) | Yes; Basic built by TestFly, the same bytes as the JDK engine. A same-origin redirect hop is sent without credentials | Yes; credentials kept on a same-origin redirect hop. On both engines, credentials never go to another origin |
Proxy (loadtest.proxy) | Yes; proxy credentials sent preemptively. Wildcard nonProxyHosts match hosts known before the run. Unset: TestFly sets no proxy | Yes; Basic proxy credentials over HTTPS need jdk.http.auth.tunneling.disabledSchemes (WARN). Unset: the JVM proxy properties apply |
TLS (loadtest.tls) | Yes; set inside the child JVM. Without loadtest.tls, Gatling's default trusts every certificate with no hostname check (INFO per run for an https target) | Yes; without loadtest.tls, the JVM default trust and hostname verification |
| Partial-run detection | Yes (lost outcomes, maxDuration stop) | Not needed: an aborted run fails with IllegalStateException |
| Recommended For | Benchmark runs, stress tests, CI pipelines | Local dev smoke tests, fast pull requests |
Gatling is an optional dependency of TestFly. Add io.gatling.highcharts:gatling-charts-highcharts to your own build to use the Gatling engine and the Gatling-only features; TestFly is built and tested against Gatling 3.16.0.
2. Automatic Engine Selection (auto)
By default, loadtest.engine: auto uses dynamic classpath inspection:
// If io.gatling.app.Gatling is found on the classpath:
// Uses GatlingEngine
// Else:
// Falls back to JdkLoadEngine without throwing ClassNotFoundException
This means developer machines without Gatling dependencies can still run the entire test suite without modification. The fallback is not silent: the first fallback in a JVM logs a WARN, and every run logs the resolved engine in its step name, for example engine=jdk (auto: Gatling not on classpath). metrics().engine() returns the engine that actually ran.
3. Explicit Engine Selection
Force an engine at the configuration or test level:
In testfly.yml
loadtest:
engine: gatling # or 'jdk'
In Code (Fluent API)
load("/api/health")
.engine("jdk") // Forces JDK engine for fast execution
.users(10)
.run();
Via Annotation
@Test
@io.testfly.loadtest.LoadTest(engine = "gatling")
public void stressTest() {
load("/api/payment/checkout").run();
}
Before any request is sent, TestFly validates the scenario for the resolved engine and fails with IllegalArgumentException on input that engine cannot run faithfully, for example a JSONPath or JMESPath outside the JDK subset, a step with both a body and form parameters, an invalid header name, regex or XPath, or a body, form parameters, a body check or a body extract(..) on a HEAD step. See Fluent API and Correlation validation.
4. Gatling Run Lifecycle
Each Gatling run executes in its own child JVM and results directory (<resultsDir>/<run-id>/):
- Every request has the
requestTimeoutSecondstimeout. The simulation has amaxDurationof the injection time (rampUp + hold, or a workload's total duration) plus, per scenario step,requestTimeoutSecondsand the longest think time, plus 30s. For a scenario with flow-control blocks, the per-step term is the worst-case duration of one iteration instead, rounded up to whole seconds: each step costsrequestTimeoutSecondsplus the longest think time,repeatandtryMaxmultiply their body,doIf/doIfOrElseandrandomSwitchcount their longest branch, and apacecounts its maximum interval. WhenmaxDurationis reached, Gatling stops and still writes its report, and TestFly flags the metrics as partial. - TestFly waits at most
maxDuration + 120sfor the child JVM. If it is still running, the child and its descendant processes are terminated and the run fails withIllegalStateException. The child is also terminated when the test thread is interrupted and when the parent JVM exits. One shutdown hook terminates every live child of the JVM together, waiting at most 20 s in total. - The child JVM starts with the main class
io.testfly.loadtest.internal.GatlingChildMain(since 1.1.0;io.gatling.app.Gatlingbefore). It reads the run's temporary configuration file, deletes it, appliesloadtest.tlsand then starts Gatling. Tools that look forio.gatling.app.Gatlingon the child's command line must match the new class. - The child JVM's heap and extra options come from
loadtest.gatling.maxHeapandjvmArgs; see Gatling child JVM. - A non-zero exit code fails the run. The exception names the exit code and includes the root error lines and the last 20 lines of
gatling-subprocess.log, with credentials (Authorization,Proxy-Authorization,Cookie,Bearertokens, bareBasic <base64>values, and token, password, secret and API-key values) masked as***. Since 1.1.0,gatling-subprocess.logitself is written through the same filter, which also masks every password, client secret and token that TestFly knows for the run (see How secrets are protected). One exception: when an SLA was registered as native Gatling assertions, exit code 2 only means "Gatling assertions failed". The run is then parsed as usual and TestFly's own SLA verdict decides. - A run in which no request could be sent at all (every step unbuildable, for example because of an unresolved
${var}) does not fail with exit code 1. TestFly returns its metrics: every request is KO with status-1. A WARN says that Gatling wrote no HTML report, because Gatling generates none when no request was sent. - TestFly records the metrics itself while the simulation runs and writes them to
testfly-metrics.jsonin the run directory: per request name the attempts, OK and KO counts, status codes and a millisecond latency histogram.LoadTestMetricsis built from this file only. TestFly does not read Gatling's report files orsimulation.log, which is a binary internal format since Gatling 3.13. If the file is missing, the run fails withIllegalStateException. - A request that cannot be built (for example one whose
${var}has no value) counts as KO with no response (status-1). Gatling's own report leaves it out, so its request totals can be lower than TestFly's. - Every declared step has an entry in
testfly-metrics.json, also a step that never ran (an untakendoIfbranch, a step skipped in atryMax):attempts0, no latency. It is a step with 0 requests andNaNp95/p99, and it does not make the run partial. - A run is partial when requests were started without a recorded outcome, or when it ran until
maxDurationstopped it. TestFly logs a WARN and setsLoadTestMetrics.partial(). Latency, status-code, error-rate andassertThroughputBelowassertions then fail, every SLA rule fails, and no result file or baseline is written from that run. - The
users/rampUp/holdloop finishes the iteration in progress whenholdends, as the JDK engine does, so a run can last up to one iteration longer thanrampUp + hold. - Gatling's HTTP warm-up request and usage analytics are disabled, so a run only connects to the system under test.
The JDK engine follows the same rule for cancellation: when the test thread is interrupted, or the run passes its safety timeout, the virtual users are stopped and the run fails with IllegalStateException. Partial metrics are never returned as a normal result. The safety timeout is the larger of rampUp + hold + cooldown + 60s and rampUp + hold plus the worst-case duration of one iteration (computed as for Gatling's maxDuration above) plus 60s. It is never shorter than before 1.1.0, and it grows with long repeat, tryMax and pace blocks.
Concurrency and throughput depend on hardware, the target service and scenario. No fixed capacity or startup time is guaranteed; measure your workload. JDK load execution uses its own transport, so ApiClient interceptors and mock rules do not automatically apply.
5. Parallel Gatling Runs
By default, Gatling runs in one JVM execute one at a time: a second run waits until the first is over, as before 1.1.0. loadtest.gatling.maxParallelRuns lets several run at once:
loadtest:
gatling:
maxParallelRuns: 2 # 1..16; default 1
maxHeap: 35% # set a heap when more than one child runs at once
-
Range.
1(the default) to16. A value below1becomes1and one above16becomes16, each with a WARN. The limit is read when each run starts, so a configuration change applies to the next run. -
Queued runs wait. A run that finds every slot in use waits for one and logs an INFO once:
[LoadTest] <name>: waiting for a Gatling run slot (2/2 in use; loadtest.gatling.maxParallelRuns). The wait has no timeout of its own. Interrupting the waiting thread cancels the run withIllegalStateException(… was cancelled while waiting for a Gatling run slot), keeps the interrupt flag, and creates no run directory and no child JVM. -
Order of a run. The
maxHeapandjvmArgscheck, then the wait for a slot, then the run directory (created and locked), the child JVM, the results, then the slot is released and run retention is applied. A queued run has no run directory yet, so it does not count towards retention. -
Isolation. Each run has its own child JVM, run directory,
gatling-subprocess.log,testfly-metrics.jsonand temporary configuration file. Run directories are created atomically, so two runs of the same scenario never share one (the second gets the next millisecond in its name). -
One JVM only. The limit applies within one JVM. Separate JVMs, such as Surefire forks or parallel CI jobs on one machine, are not coordinated: each allows
maxParallelRunsruns, so three JVMs withmaxParallelRuns: 2can run up to six Gatling children together. Their run directories stay separate, and a run in progress keeps its directory locked against other JVMs' retention sweeps. -
Console output. The start and end lines of each run, and its
Gatling native assertions failedline, carry its run directory name (logger lines do not), so the output of parallel runs can be told apart:[LoadTest] [Checkout-1767225600000] Starting Gatling engine: Checkout (10 users, rampUp=10s, hold=30s)[LoadTest] [Checkout-1767225600000] Gatling execution complete. Parsing results...
Memory
Each child JVM without maxHeap takes the JVM default of 25% of the physical or container RAM, on top of the test JVM. With more than one run at a time, set loadtest.gatling.maxHeap so that all children fit, for example a fixed size such as 1g or a share such as 35% for two runs. When maxParallelRuns is above 2 and maxHeap is not set, TestFly logs a WARN once per JVM: N parallel runs x the JVM default of 25% of RAM = X% of RAM, with a suggested maxHeap of about 75/N percent, rounded down and at least 5% (for example 25% for 3 runs, 18% for 4).
CPU and measurement fidelity
Parallel runs on one host compete for CPU, memory and network. Latency measured under that contention is higher and noisier than in a run alone. Parallel runs make a suite of load tests finish sooner; they do not make the measurement more accurate. Keep maxParallelRuns: 1 for runs whose latency figures, SLAs or baselines matter, or give each run its own host (see Distributed load).
Fixed ports
A child JVM opens no listening port by default. An option that opens a fixed port, such as -Dcom.sun.management.jmxremote.port=9010 in jvmArgs or JAVA_TOOL_OPTIONS, collides when two children run at once. Do not set a fixed port with maxParallelRuns above 1.