Build executable JAR for Gatling load test

后端 未结 6 1154
感动是毒
感动是毒 2020-12-30 02:01

I am new to Gatling (2.1.2) and want to do a small prototype project to show to my colleagues.

According to the quick start page, there are several ways I can run a

6条回答
  •  自闭症患者
    2020-12-30 02:46

    I tried to do something similar. I could not use Maven as well. I will try to remember how I did this.

    1) I have configured maven-assembly-plugin to generate single JAR with dependencies like this:

    
        maven-assembly-plugin
        
            
                jar-with-dependencies
            
        
    
    

    You need to ensure all required libraries (gatling, scala runtime, zinc compiler) are present on your resulting classpath.

    2) Check the scope of your dependencies as Maven packs only classes defined with scope=compile by default. The most simple way is probably to use no test dependencies.

    3) Create a launch script, e.g. launch.sh. It should contain something like this:

    #!/bin/sh
    USER_ARGS="-Dsomething=$1"
    COMPILATION_CLASSPATH=`find -L ./target -maxdepth 1 -name "*.jar" -type f -exec printf :{} ';'`
    JAVA_OPTS="-server -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=42 -Xms512M -Xmx2048M -XX:+HeapDumpOnOutOfMemoryError -XX:+AggressiveOpts -XX:+OptimizeStringConcat -XX:+UseFastAccessorMethods -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false ${JAVA_OPTS}"
    java $JAVA_OPTS $USER_ARGS -cp $COMPILATION_CLASSPATH io.gatling.app.Gatling -s your.simulation.FullClassName
    

    To explain, I took gatling`s own launch script for inspiration. Note mainly the presence of target directory in classpath parameter definition.

    4) Compile your compiled target directory and launch.sh to a single directory and distribute this (e.g. as archive). Then you can the scenarios by executing ./launch.sh.

    I know this is not a standard solution, but it worked for me. Hopefully it will help you too. If you have any problems or tips to improve, please share with us.

提交回复
热议问题