Skip to main content
When I was on your side of the keyboard, developing cool and funny applications (more or less :D), load tests were (most of the time) executed a few days before going live. We sometimes discover rabbits in the hole, doing too much stuff, and then, we switch to firefighter mode to solve all of the issues. That was not a great experience. All applications should be load tested, from the beginning and along the way, as a default. We will see in this guide how to set up your Upsun project for running automatic load tests on each push on your Upsun preview environments. In this article, we’ll add an Activity Script integration, that will in turn call a runtime operation, which will then execute a Gatling simulation to load test our environment. Gatling CORP is a french company and they provide tools to load test your application, with two versions of their product: a Community (free) and Cloud (Enterprise) version of their product.
Note:If you want to learn more about what and why it is important to load test your application, please see this blog post from Peter Dukta (Gatling), you will find everything you want.

Gatling and load tests

Assumptions:
  • You already have a project hosted on Upsun.
  • You have the Upsun CLI installed.

Install the Javascript SDK

First step is to install the Javascript SDK from Gatling documentation. To install it locally, run the following commands:

Install dependencies

To install Gatling libraries during the build hook, add the following in your .upsun/config.yaml file:
Then add your config.yaml file to your Git history:

Define a simulation

Create a new gatling/javascript/src/myfirstsimulation.gatling.js file with the following source code:
For your homepagescenario scenario to load test your dynamic preview environment url, we will inject an uri parameter (line 6) during the run command call (see next steps).
Then add your myfirstsimulation.gatling.js file to your Git history:

Get environment URI

To dynamically get the current environment URI, from the PLATFORM_ROUTES environment variable, you can use an .environment file that will dynamically build it. Create a new .environment file, at the root of your application with the following lines:
Then add this .environment file to your Git history.

Define runtime operation

Runtime operations allow you to trigger one-off commands or scripts on your application (preview) container. We will then be able to execute it using an Activity script integration. Update your .upsun/config.yaml file with the following:
The npx gatling run command has a uri=$URI parameter, using the previously created URI environment variable.
Then add your .upsun/config.yaml file to your Git history.

Create activity script

Create a new Javascript file (our Activity script file) at the root of your source code, gatling-worker.js (source here) with the following command line:
This activity script uses an API Token, as an environment variable, to connect to the current environment and execute the previously defined runtime operation using the Upsun API. We need to define this environment variable for the integration of our activity script, and later add an API Token environment variable.
You will be able to run this runtime operation on demand from both command line (CLI) and the Console.

Add integration

Let say we would like to load tests our environment, each time we push new source code on it (corresponding event is environment.push).
A complete list of possible events is available as the Activity script type definition. Any of those Activity Script types can be added as an event list in the --events event1,event2,... option.

API tokens

First, get the previous integration ID using the following command:
Then, create a new API Token from the Console, keep the value in your hand, and replace it in this terminal command:
Replace <INTEGRATION_ID>and <API_TOKEN> with the corresponding values previously create
You can verify that the variable has been created with this command:

Time to test

To test it, create a new feature branch and push an update to your preview environment, you will see an activity script event that will contain logs of your load tests. When opening the log of the gatling_myfirstsimulation runtime operation, you will see the full load test report.

Online report

At the end of this report, you will see that Gatling simulation generates a local HTML report to get the full view of the simulation.
To allow remote access to this HTML report file, you just need to allow a new routes by adding a new web.locations rule to your application. To generate in your report the corresponding report url, you will also need to change your runtime operation to display it. In your .upsun/config.yaml file, update the following:
Then deploy this change:
When deploy is finished, you will find, at the end of the runtime operation logs, the generated url of your Gatling load test report and you just need to copy/paste it to your browser, something like: Gatling Community Edition view, running on an Upsun environment at /gatling, showing response time ranges for 120 requests to the homepage as defined by simulation myfirstsimulation.

Troubleshooting

If during deployment, when installing Gatling, you get an error telling that the process has been killed, this means that your container is not having enough RAM.
As the Gatling javascript SDK is using Graalvm JDK to run load tests locally on the application container, resources (RAM) needs to be adjusted. By default, PHP containers use a HIGH_CPU container profile, which means 0.5 CPU and 224MB of RAM.
We need to increase the allocated RAM by updating the container profile of our application container to BALANCED (0.5CPU & 1088MB RAM)

Conclusions

Load testing your application is crucial if you are running applications with a lot of traffic spikes or if you’re facing TV show effects. In this guide, we took a look at how to set up an on-demand set of load tests with Gatling community edition that could be triggered (and observed) on a new Upsun preview environment using a runtime operation. Some next steps could include automatically triggering these operations when preview environments (merge/pull requests) are opened. An additional caveat to consider is that load testing in this way — running Gatling within Upsun application containers — will consume resources in your projects. In a follow-up posts, we will see how to use the Gatling Cloud (and so, external resources) to run load tests. Remain up-to-date on the latest from us over on our social media and community channels: DEV.to, Reddit, and the Upsun Community Forum.
Last modified on May 12, 2026