Change shell script to work with play
Added an argument to the script to take [play-zip|jar] to distinguish between the frameworks to test
Updated README
Cleanup
MODIFY
dd-java-agent/benchmark-integration/README.md
dd-java-agent/benchmark-integration/README.md
@@ -10,14 +10,22 @@ Integration level performance tests for the Datadog Java Agent.
* nc
## Running a Test
-1. Build the shadow jar for the server you wish to test against.
+1. Build the shadow jar or the distribution zip for the server you wish to test against.
2. Run the performance test script passing in the agent jars you wish to test.
3. (optional) Save test results csv and ponder the great mysteries of performance optimization.
### Example
+#### Jetty
```
./gradlew dd-java-agent:benchmark-integration:jetty-perftest:shadowJar
-# Compare a baseline (no agent) to the 0.2.10 and 0.2.9 releases.
-/usr/local/bin/bash ./run-perf-test.sh jetty-perftest/build/libs/jetty-perftest-*-all.jar NoAgent ../benchmark/releases/dd-java-agent-0.2.10.jar ../benchmark/releases/dd-java-agent-0.2.9.jar
+# Compare a baseline (no agent) to the 0.18.0 and 0.19.0 releases.
+/usr/local/bin/bash ./run-perf-test.sh jar jetty-perftest/build/libs/jetty-perftest-*-all.jar NoAgent ~/Downloads/dd-java-agent-0.18.0.jar ~/Downloads/dd-java-agent-0.19.0.jar
+cp /tmp/perf_results.csv ~/somewhere_else/
+```
+#### Play
+```
+./gradlew :dd-java-agent:benchmark-integration:play-perftest:dist
+# Compare a baseline (no agent) to the 0.18.0 and 0.19.0 releases.
+/usr/local/bin/bash ./run-perf-test.sh play-zip play-perftest/build/distributions/playBinary NoAgent ~/Downloads/dd-java-agent-0.18.0.jar ~/Downloads/dd-java-agent-0.19.0.jar
cp /tmp/perf_results.csv ~/somewhere_else/
```

MODIFY
dd-java-agent/benchmark-integration/play-perftest/app/controllers/HomeController.scala
dd-java-agent/benchmark-integration/play-perftest/app/controllers/HomeController.scala
@@ -9,25 +9,20 @@ import play.api.mvc._
/**
* This controller creates an `Action` to handle HTTP requests to the
- * application's home page.
+ * application's work page which does busy wait to simulate some work
*/
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
/**
- * Create an Action to render an HTML page.
- *
- * The configuration in the `routes` file means that this method
- * will be called when the application receives a `GET` request with
- * a path of `/`.
+ * Create an Action to perform busy wait
*/
def doGet(workTimeMS: Option[Long], error: Option[String]) = Action { implicit request: Request[AnyContent] =>
error match {
case Some(x) => throw new RuntimeException("some sync error")
case None => {
- //val workVal: String = request.queryString("workTimeMS").headOption.getOrElse("")
var workTime = workTimeMS.getOrElse(0l)
scheduleWork(workTime)
- Ok("DONE WORK IN " + workTime + " MS")
+ Ok("Did " + workTime + "ms of work.")
}
}

DELETE
dd-java-agent/benchmark-integration/play-perftest/conf/messages
-# https://www.playframework.com/documentation/latest/ScalaI18N

MODIFY
dd-java-agent/benchmark-integration/play-perftest/play-perftest.gradle
dd-java-agent/benchmark-integration/play-perftest/play-perftest.gradle
@@ -11,55 +11,9 @@ model {
play {
platform play: playVersion, scala: scalaVersion, java: '1.8'
injectedRoutesGenerator = true
-//
-// sources {
-// scala {
-// source.srcDir "play-perftest-server/app"
-// }
-// routes {
-// source.srcDir "play-perftest-server/conf"
-// }
-// }
-
-
}
}
}
-//dist {
-// into(project.name) {
-// from 'play-perftest-server'
-// include 'conf/*'
-// }
-//}
-// EXAMPLE: How to add parameter to Scala compiler
-// Another option is documented here:
-// https://docs.gradle.org/current/userguide/play_plugin.html#sec:configuring_compiler_options
-//
-// See other configurations for ScalaCompile task here:
-// https://docs.gradle.org/current/dsl/org.gradle.api.tasks.scala.ScalaCompile.html
-//
-// tasks.withType(ScalaCompile) {
-// scalaCompileOptions.additionalParameters = [
-// "-deprecation",
-// "-verbose"
-// ]
-// }
-
-// EXAMPLE: How to add JVM parameters when running `runPlayBinary`.
-// See other configurations for PlayRun here:
-// https://docs.gradle.org/current/dsl/org.gradle.play.tasks.PlayRun.html
-//
-// tasks.withType(PlayRun) {
-// forkOptions.jvmArgs = ['-Dplay.http.secret.key=yadayada']
-// }
-
-// EXAMPLE: How to add JVM parameters to the script created by `stage`.
-// See more details here:
-// https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/application/CreateStartScripts.html
-//
-//tasks.withType(CreateStartScripts) {
-// defaultJvmOpts = ['-Dplay.http.secret.key=yadayada', '-Dhttp.port=8080']
-//}
dependencies {
play "com.typesafe.play:play-guice_$scalaVersion:$playVersion"

MODIFY
dd-java-agent/benchmark-integration/run-perf-test.sh
dd-java-agent/benchmark-integration/run-perf-test.sh
# A script for measuring a server's throughput with or without a java agent.
test_csv_file=/tmp/perf_results.csv
server_output=/tmp/server_output.txt
-server_jar=$1
-agent_jars="${@:2}"
+server_type=$1
+server_package=$2
+agent_jars="${@:3}"
server_pid=""
agent_pid=$(lsof -i tcp:8126 | awk '$8 == "TCP" { print $2 }')
-
-if [ "$server_jar" = "" ]; then
- echo "usage: ./run-perf-test.sh path-to-server-jar path-to-agent1 path-to-agent2..."
+if [[ "$server_package" = "" ]] || [[ "$server_type" != "play-zip" && "$server_type" != "jar" ]]; then
+ echo "usage: ./run-perf-test.sh [play-zip|jar] path-to-server-package path-to-agent1 path-to-agent2..."
echo ""
- echo "path-to-server-jar : Must be a jar which creates an http server on local port 8080 when started as a jar."
+ echo "[play-zip|jar] : Specify whether the server will be in zip format (play server) or jar format"
+ echo "path-to-server-package : Must be a jar or binary zip package which creates an http server on local port 8080 when started."
+ echo " Note: if the server package is a zip, then the script will attempt to unzip to a temp directory and run the server from there."
echo "path-to-agent* : Each must be a javaagent jar, or NoAgent."
echo ""
echo "Example: This will run the perf tests against myserver.jar. It will run against no agent as a baseline, then against myagent-1.0.jar."
@@ -41,7 +43,9 @@ fi
echo ""
echo ""
-# Start up server jar passed into the scipt
+unzipped_server_path=""
+
+# Start up server passed into the script
# Blocks until server is bound to local port 8080
function start_server {
agent_jar="$1"
@@ -49,8 +53,44 @@ function start_server {
if [ "$agent_jar" != "" -a -f "$agent_jar" ]; then
javaagent_arg="-javaagent:$agent_jar -Ddatadog.slf4j.simpleLogger.defaultLogLevel=off -Ddd.writer.type=$writer_type -Ddd.service.name=perf-test-app"
fi
- echo "starting server: java $javaagent_arg -jar $server_jar"
- { /usr/bin/time -l java $javaagent_arg -Xms256m -Xmx256m -jar $server_jar ; } 2> $server_output &
+
+ if [ "$server_type" = "jar" ]; then
+ echo "starting server: java $javaagent_arg -jar $server_package"
+ { /usr/bin/time -l java $javaagent_arg -Xms256m -Xmx256m -jar $server_package ; } 2> $server_output &
+ else
+ # make a temp directory to hold the unzipped server
+ unzip_temp=`mktemp -d`
+ # perform the unzipping of the play zip
+ unzip ${server_package} -d ${unzip_temp} &> /dev/null
+
+ if [ $? -eq 0 ]; then
+ echo "Unzipped server package at ${unzip_temp}"
+ else
+ echo "Failed to unzip server package to ${unzip_temp}"
+ exit 2
+ fi
+
+ # get the unzipped directory name
+ unzipped_dirname=`basename ${unzip_temp}/*`
+ # unzipped server location, will be removed when the server is stopped
+ unzipped_server_path=${unzip_temp}
+
+ java_opts_env='JAVA_OPTS="'${javaagent_arg}'"'
+ # it appears the binary script will always be named playBinary at the time of writing
+ # no matter what the zip file is named.
+ play_script=${unzipped_server_path}/${unzipped_dirname}/bin/playBinary
+
+ # have to use env to set JAVA_OPTS because of a gradle play plugin bug:
+ # https://github.com/gradle/gradle/issues/4471
+ if [ "$agent_jar" != "" -a -f "$agent_jar" ]; then
+ utility_cmd="env JAVA_OPTS=${javaagent_arg} ${play_script}"
+ else
+ utility_cmd="${play_script}"
+ fi
+
+ echo "starting server: ${utility_cmd}"
+ { /usr/bin/time -l ${utility_cmd} ; } 2> $server_output &
+ fi
# Block until server is up
until nc -z localhost 8080; do
@@ -67,6 +107,11 @@ function stop_server {
kill $server_pid
wait
server_pid=""
+ # clean up the unzipped server
+ if [[ ${unzipped_server_path} != "" ]] && [[ ${server_type} = "play-zip" ]] && [[ -d ${unzipped_server_path} ]]; then
+ echo "Cleaning up unzipped server at "${unzipped_server_path}
+ rm -rf ${unzipped_server_path}
+ fi
}
# Warmup and run wrk tests on a single endpoint.

Change shell script to work with play

- Added an argument to the script to take [play-zip|jar] to distinguish between the frameworks to test
- Updated README
- Cleanup