Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-207: JMH benchmarking #1512

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,38 @@ In order to debug in Intellij:
5. Run the local firecloud docker with `./config/docker-rsync-local-orch.sh` from the root directory
6. In Intellij, choose your debug configuration and run 'debug'.



## Benchmarking

Benchmarks reside in the [benchmarks](benchmarks) subdirectory,
and are accessible via an `sbt` subproject named `bench`.

Benchmarks are powered by [JMH](https://github.com/openjdk/jmh)
and integrated into sbt using the [sbt-jmh plugin](https://github.com/sbt/sbt-jmh).

To execute benchmarks:
```
sbt bench/Jmh/run
```

To see options for running benchmarks:
```
sbt "bench/Jmh/run -h"
```
Example of specifying options when running benchmarks (this example sets 3 iterations,
2 warmup iterations, and one fork):
```
sbt "bench/Jmh/run -i 3 -wi 2 -f 1"
```

Running benchmarks takes a while, especially when specifying more iterations/warmups/forks.
Of course, using more iterations/warmups/forks is also more accurate. Benchmark output is fairly verbose;
look for the final summary that will look something like:
```
[info] Benchmark Mode Cnt Score Error Units
[info] TsvFormatterBenchmark.tsvSafeStringNoTab thrpt 3 85746770.866 ± 112486692.134 ops/s
[info] TsvFormatterBenchmark.tsvSafeStringWithTab thrpt 3 30601083.552 ± 53318975.049 ops/s
```


1 change: 1 addition & 0 deletions benchmarks/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.10.6
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.broadinstitute.dsde.firecloud.utils

import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.infra.Blackhole

class TsvFormatterBenchmark {

@Benchmark
def tsvSafeStringNoTab(blackHole: Blackhole): String = {
val result = TSVFormatter.tsvSafeString("foo")
blackHole.consume(result)
result
}

@Benchmark
def tsvSafeStringWithTab(blackHole: Blackhole): String = {
val result = TSVFormatter.tsvSafeString("foo\tbar")
blackHole.consume(result)
result
}

}
21 changes: 18 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import Settings._
import Testing._
import Settings.*
import Testing.*
import pl.project13.scala.sbt.JmhPlugin
import spray.revolver.RevolverPlugin

lazy val root = project.in(file("."))
.settings(rootSettings:_*)
.settings(rootSettings *)
.withTestSettings
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these first few changes are just to get rid of intellij syntax warnings in this file.


enablePlugins(RevolverPlugin)

// JMH subproject for benchmarking
lazy val bench = project.in(file("benchmarks"))
.dependsOn(root % "compile->compile")
.disablePlugins(RevolverPlugin)
.enablePlugins(JmhPlugin)
.settings(
scalaVersion := (root / scalaVersion).value,
// rewire tasks, so that 'bench/Jmh/run' automatically invokes 'bench/Jmh/compile'
// and 'bench/Jmh/compile' invokes root's 'compile'
Jmh / compile := (Jmh / compile).dependsOn(Compile / compile).value,
Jmh / run := (Jmh / run).dependsOn(Jmh / compile).evaluated
)


Revolver.enableDebugging(port = 5051, suspend = false)

// When JAVA_OPTS are specified in the environment, they are usually meant for the application
Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.2.2")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7")

addDependencyTreePlugin
Loading