Every virtual user in a Gatling simulation carries its own Session — an isolated, mutable key-value store that persists throughout the user’s lifecycle. The Session is how you inject dynamic data (usernames, tokens, IDs) into requests and extract values from responses for reuse in later steps. Without per-user state, all virtual users would replay identical requests, defeating the purpose of realistic load testing and potentially only exercising application caches rather than real business logic. This page provides an overview of the session sub-system. Use the links below to jump to the topic you need.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/gatling/gatling.io-doc/llms.txt
Use this file to discover all available pages before exploring further.
Sub-Topics
Session API
Programmatically read and write session attributes using
get, set, setAll, remove, reset, and state management methods.Expression Language (EL)
Use
#{key} syntax in strings to dynamically interpolate session attributes into request parameters, URLs, and headers.Feeders
Load dynamic test data from CSV, JSON, JDBC, Redis, or custom sources and inject it into the session automatically per virtual user.
Functions
Pass lambda functions anywhere Gatling accepts an Expression to compute values dynamically from the session at runtime.
Concepts
Why Per-User State Matters
In most load testing scenarios, virtual users must not share the same data. If they do, you risk:- Cache pollution: responses are served from application caches and never reach the real backend logic.
- JIT skew: the JVM’s Just-In-Time compiler makes aggressive optimizations based on observed code paths. Identical requests create an unrealistically narrow code path, making benchmark results irrelevant to production behavior.
What Is a Session?
A Session is essentially aMap<String, Object>: a string-keyed map of named attributes belonging to one specific virtual user. Every Action in a Gatling scenario receives the current Session and passes a (potentially modified) Session to the next Action.
Injecting Data Into the Session
There are three ways to load data into a virtual user’s session:- Feeders — automated data injection from external sources (CSV, JSON, JDBC, etc.)
- Check
saveAs— extract values from responses and store them (see Checks) - Session API — programmatic read/write in
execfunctions
Retrieving Data From the Session
Once data is in the session, you can use it in two ways:- Expression Language (EL) — the
#{key}syntax in string parameters - Session API — calling
session.get("key")inside functions
Session API Quick Reference
Setting Attributes
- Java
- JavaScript / TypeScript
Getting Attributes
- Java
- JavaScript / TypeScript
Virtual User Properties
- Java
- JavaScript / TypeScript
Session State Management
- Java
- JavaScript / TypeScript