Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active December 15, 2025 17:29
Show Gist options
  • Select an option

  • Save dacr/88c797b05ee968be145eccc77e498888 to your computer and use it in GitHub Desktop.

Select an option

Save dacr/88c797b05ee968be145eccc77e498888 to your computer and use it in GitHub Desktop.
Just ONE ammonite script file to execute a load performance test using gatling ! / published by https://github.com/dacr/code-examples-manager #ea7a4259-9461-44a8-99fa-1ec6ec3c48ed/443c1c94e20bb3b5a5b8a685bf191fd3cce8b16b
// summary : Just ONE ammonite script file to execute a load performance test using gatling !
// keywords : scala, gatling, ammonite, scala, load-test, performance
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : ea7a4259-9461-44a8-99fa-1ec6ec3c48ed
// created-on : 2018-09-22T07:41:07Z
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
//> using scala 2.13
//> using dep io.gatling:gatling-http:3.10.5
//> using dep io.gatling:gatling-app:3.10.5
//> using dep io.gatling:gatling-core:3.10.5
//> using dep io.gatling.highcharts:gatling-charts-highcharts:3.10.5
//> using dep ch.qos.logback:logback-classic:1.5.18
/*
This example can be run locally :
```
docker run -p 8099:80 kennethreitz/httpbin
export HTTPBIN_BASE_URL=http://localhost:8099/
scala-cli gatling-simple.sc
```
*/
import io.gatling.app.Gatling
import io.gatling.core.config.GatlingPropertiesBuilder
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import org.slf4j.{LoggerFactory, Logger}
val rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME).asInstanceOf[ch.qos.logback.classic.Logger]
rootLogger.setLevel(ch.qos.logback.classic.Level.ERROR)
class GatlingSimple extends Simulation {
val httpbinBaseURL = scala.util.Properties.envOrElse("HTTPBIN_BASE_URL", "https://httpbin.org")
def config = {
http
.baseUrl(httpbinBaseURL)
.userAgentHeader("curl/7.58.0")
.disableFollowRedirect
}
def assertions = List(
global.responseTime.mean.lt(90),
global.successfulRequests.percent.gt(90)
)
def scn =
scenario("Simple load").during(30.seconds) {
exec(
http("get200")
.get("/")
.check(status.is(200))
)
.pause(1000.milliseconds, 2000.milliseconds)
.exec(
http("get401")
.get("/status/401")
.check(status.is(401))
)
.pause(2000.milliseconds, 4000.milliseconds)
}
setUp(scn.inject(rampUsers(10).during(10.seconds)))
.protocols(config)
.assertions(assertions)
}
val props =
new GatlingPropertiesBuilder()
.simulationClass(classOf[GatlingSimple].getName)
.resultsDirectory("/tmp")
// .noReports()
.build
Gatling.fromMap(props)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment