Pack simulation with dependencies in jar

Hi all,

I’m fairly new to programming - especially Scala - in general, but I’ve managed to work with Gatling (create custom feeders, save, re-use and edit elements from responses etc.) without any problem. So a big praise for the ease of use of your DSL, documentation and community!

Now that I set up a sufficient scenario to do some basic performance tests on our framework I want to run it on a server via one jar file including all dependencies. I managed to create a jar using the following method. If I run it I get the following IOException:

Exception in thread “main” java.lang.ExceptionInInitializerError
at Engine$delayedInit$body.apply(Engine.scala:7)
at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:76)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30)
at scala.App$class.main(App.scala:60)
at Engine$.main(Engine.scala:4)
at Engine.main(Engine.scala)
Caused by: java.io.IOException: The filename, directory name, or volume label syntax is incorrect
at java.io.WinNTFileSystem.canonicalize0(Native Method)
at java.io.Win32FileSystem.canonicalize(Unknown Source)
at java.io.File.getCanonicalPath(Unknown Source)
at scala.tools.nsc.io.Path.toCanonical(Path.scala:100)
at scala.tools.nsc.io.Path.isSame(Path.scala:228)
at scala.tools.nsc.io.Path.parents(Path.scala:173)
at IDEPathHelper$.(IDEPathHelper.scala:7)
at IDEPathHelper$.(IDEPathHelper.scala)
… 11 more

I guess it has to do with the paths configured not being valid when running it from a jar. I still got the default paths configured in IDEPathHelper.scala

val gatlingConfUrl = getClass.getClassLoader.getResource(“application.conf”).getPath
val projectRootDir = File(gatlingConfUrl).parents(2)

val mavenSourcesDirectory = projectRootDir / “src” / “main” / “scala”
val mavenResourcesDirectory = projectRootDir / “src” / “main” / “resources”
val mavenTargetDirectory = projectRootDir / “target”
val mavenBinariesDirectory = mavenTargetDirectory / “main-classes”

val dataDirectory = mavenResourcesDirectory / “data”
val requestBodiesDirectory = mavenResourcesDirectory / “request-bodies”

val recorderOutputDirectory = mavenSourcesDirectory
val resultsDirectory = mavenTargetDirectory / “results”

Anybody has experience with packing the whole simulation in an executable jar and can help me? Are there any best practices or examples for running simulations from a server?

Thanks in advance.

Roy

Thanks for your kind words, much appreciated.

Loading resources from classpath just made it into master yesterday evening: https://github.com/excilys/gatling/commit/b8d273a30d877a4b84e8df43f1c2bac199f0951d
We have yet to investigate if it can be backported into 1.5 branch. Pierre, WDYT?

Cheers,

Stéphane

Hi Stéphane,

Thanks for your quick reply! I don’t understand your answer completely.

Maybe it is better to phrase my question in more general terms.

  1. I want to run my simulation from a server
  2. Set some variables for the number of users and simulation time
  3. Let it run for a couple of days
    I thought an executable jar would be the most handy solution, but maybe there are better solutions?

Roy

Roy,

It’s certainly possible to build an “uberjar” but sometimes it’s kind of a pain. How much control do you have over your server environment? Do you have the option of using “sbt” there?

I have a project where I have basically the same requirements that you’ve outlined and my solution was to launch the simulation using sbt. In my sbt build file I simply have a list of gatling dependencies (which are available from public maven repos) and a small configuration tweak that tells it the “main class” to run. sbt handles the downloading of all of the gatling jars and setting up the classpath. You could do the same thing with maven.

I also have a need for configuring the number of users/repetitions/etc., so I wrote a thin wrapper class that reads my configuration parameters (from environment variables and json files), instantiates the simulation objects, and then hands control back over to Gatling to run the sim.

If any of that sounds useful to you, let me know and I’ll be happy to pass along some example code.

What’s the problem with the standard bundle and launch scripts, then?

Sorry Stéphane, as I said I’m not a very experienced programmer. What is the standard way of deploying and launching your Gatling simulation on a server easily?

Hi Chris,

Thanks for you thinking with me here. Finally we want to use Gatling for more applications, so we want to automatize this process as much as possible. Why did you choose sbt over Maven? I guess Maven is the standard way Stéphane is mentioning (below), or am I wrong?

Anyway I’m very much interested in sbt and example code. Your solution sound very elegant.

Roy

Just use the regular archive (zip or tar), decompress, drop your files in the expected user-files sub folders and launch the bat or sh script.
Beware that if you want to run a very long simulation, you’ll have to edit the simulation timeout in conf/gatling.conf.

Have you read the documentation? https://github.com/excilys/gatling/wiki/Getting-Started

Thank you! I will give it a try this week. I read the documentation thoroughly, but I didn’t relate the command line interface to running it on a server.

Sorry… as I said not much experience…

@Chris: I will also look into sbt though, sounds pretty handy and elegant.

Roy,

Definitely use the bundle approach that Stéphane mentions if it suits your needs.

For us, we have a lot of different servers we want to run on and we didn’t want to deal with copying the binaries around all over the place. The sbt / maven approach allows me to create a very small git repo that contains just the build.sbt and my simulation / user files, and then that git repo can be checked out on any machine and launched w/o having to manually copy around the binaries. You could accomplish the same thing in maven. Here’s (roughly) what my build.sbt looks like if anyone is interested :slight_smile:

Thanks Chris! I will keep your solution in mind though, hopefully our performance testing efforts will one day grown to such a stage where this is necessary.