Skip to main content

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​

FeatureGatling Engine (gatling)JDK Engine (jdk)
Underlying TechGatling 3.16.0 + Netty async IOJava 21+ HttpClient + Virtual Threads
Classpath DependencyOptional (gatling-charts-highcharts)Built into Java standard library
Process IsolationDedicated forked JVM subprocessRuns in-process on test worker thread
Native ReportInteractive Highcharts HTML reportIntegrated TestFly HTML dashboard
Subprocess Loggatling-subprocess.logStandard TestFly logs
Metrics SourceTestFly's own sidecar testfly-metrics.json (counts, status codes, millisecond latency histogram)Measured in-process
Latency Percentilesp50, p75, p90, p95, p99 (exact, linear interpolation)p50, p75, p90, p95, p99 (exact, linear interpolation)
Latency PopulationRequests that received an HTTP responseAlso includes the elapsed time of connection failures and timeouts
HTTP Status CodesReal status per responseReal status per response
JSONPath in checksFull 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 caseYes, 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 engineYes
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 protectionXPath 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 classpathSubset 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 methodsGET, POST, PUT, PATCH, DELETE, HEAD, OPTIONSSame
Default body Content-TypeInferred from the declared body (JSON, XML or text); a user-set header winsSame rule
users / rampUp / holdYes (whole seconds)Yes (whole seconds)
Workload models (workload(...))YesNo: rejected before any request
Simulations (loadSimulation(...))YesNo: rejected before any request
Flow control (repeat, doIf, doIfOrElse, randomSwitch, group, tryMax, pace)Yes; a group also appears in Gatling's reportYes, 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/p99Same
SLAs (sla(...))Yes, evaluated by TestFly; also shown as native assertions in Gatling's reportYes, evaluated by TestFly
Baselines and testfly-loadtest-result.jsonYesYes
Feeder strategies (queue, circular, randomOrder, shuffle) and several feedersYes, 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 endsThe user ends; same flag and WARN
CSV parsingSame RFC 4180 parser; above 100,000 records the child JVM reads the file again and checks its size and modification timeParsed once in the test JVM
Custom feedersIts 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 credentialsYes; 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 proxyYes; 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 detectionYes (lost outcomes, maxDuration stop)Not needed: an aborted run fails with IllegalStateException
Recommended ForBenchmark runs, stress tests, CI pipelinesLocal 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 requestTimeoutSeconds timeout. The simulation has a maxDuration of the injection time (rampUp + hold, or a workload's total duration) plus, per scenario step, requestTimeoutSeconds and 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 costs requestTimeoutSeconds plus the longest think time, repeat and tryMax multiply their body, doIf/doIfOrElse and randomSwitch count their longest branch, and a pace counts its maximum interval. When maxDuration is reached, Gatling stops and still writes its report, and TestFly flags the metrics as partial.
  • TestFly waits at most maxDuration + 120s for the child JVM. If it is still running, the child and its descendant processes are terminated and the run fails with IllegalStateException. 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.Gatling before). It reads the run's temporary configuration file, deletes it, applies loadtest.tls and then starts Gatling. Tools that look for io.gatling.app.Gatling on the child's command line must match the new class.
  • The child JVM's heap and extra options come from loadtest.gatling.maxHeap and jvmArgs; 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, Bearer tokens, bare Basic <base64> values, and token, password, secret and API-key values) masked as ***. Since 1.1.0, gatling-subprocess.log itself 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.json in the run directory: per request name the attempts, OK and KO counts, status codes and a millisecond latency histogram. LoadTestMetrics is built from this file only. TestFly does not read Gatling's report files or simulation.log, which is a binary internal format since Gatling 3.13. If the file is missing, the run fails with IllegalStateException.
  • 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 untaken doIf branch, a step skipped in a tryMax): attempts 0, no latency. It is a step with 0 requests and NaN p95/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 maxDuration stopped it. TestFly logs a WARN and sets LoadTestMetrics.partial(). Latency, status-code, error-rate and assertThroughputBelow assertions then fail, every SLA rule fails, and no result file or baseline is written from that run.
  • The users/rampUp/hold loop finishes the iteration in progress when hold ends, as the JDK engine does, so a run can last up to one iteration longer than rampUp + 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) to 16. A value below 1 becomes 1 and one above 16 becomes 16, 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 with IllegalStateException (… 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 maxHeap and jvmArgs check, 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.json and 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 maxParallelRuns runs, so three JVMs with maxParallelRuns: 2 can 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 failed line, 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.