Gist explaining a way to add long-living connections to Gatling and create scenarios that reuse the connection(s) to put load on the target system.
I have used the gatling-kafka plugin available on GitHub as inspiration.
Note that the code snippets provided here do not complile right out of the box. You will have to add some dependencies, and code yourself to make things work.
The code snippets are based on my experiments using the following component versions:
- SBT 0.13.8
- Scala 2.11.7
- Gatling 2.1.7
See build.sbt for details
You store connection information on the Gatling session object, allowing the
subsequent steps in the scenario to use the correct connection. This is
done by storing a connection object: session.set("someConnectionName", connObject)
.
Your scenario has to make sure it creates 1 connection as the first step, then uses that connection in its remaining steps, and finally closes the connection as its last step.
The load test is then executed by starting a couple of users, each playing the scenario. One connection is created per user, mimicking the production situation.
The creation action is executed first, and it:
- opens the connection (results in some connection reference/object/actor)
- stores the connection reference/object/actor on the session object
- sends a continuation message (the updated session object) to the next actor
The regular actions that are added to the scenario each perform the following steps:
- retrieve the connection object from the session object
- perform some action via the connection
- send a continuation message (the session object) to the next actor
The termination action is executed last and it:
- retrieves the connection object from the session
- closes the connection (and destroys the connection reference/object/actor if needed)
- removes the connection reference/object/actor from the session object
- sends a continuation message (the updated session object) to the next actor
If needed you can add timing recording to the actions, see Metrics.scala
Gatling scenarios are not the actual scenarios, but more a template that is used to create action actors whenever they are executed. A DSL is suggested (Predef.scala) that creates statement wrappers around the ActionBuilders. ActionBuilders are objects that implement the build() method, which creates an Action actor whenever it is called. The actors are the ones that open the connection, or call the actions, or close the connection.
-
Builders
-
Action actors
Usage example: BasicSimulation.scala