Triplequote Hydra (or simply Hydra) is a drop-in replacement of the regular Scala compiler. Its design goal is to take advantage of the many cores available in modern hardware to parallelize compilation of Scala sources.
Hydra integrates seamlessly with sbt thanks to the
sbt-hydra sbt plugin. Setting up Hydra in your sbt build is a simple two steps process, but let's start by fulfilling all requirements.
- sbt 0.13.13 or above / 1.0 or above. To avoid errors, please start by checking your project is using a supported sbt version (read the sbt documentation for how to specify the sbt version).
- If using Coursier, make sure to use version 1.0.0 or later as there are incompatibilities between Hydra and older versions of Coursier.
- for Scala 2.11: 2.11.8 or above
- for Scala 2.12: 2.12.1 or above
- Oracle Java 1.8
Navigate to the project on which you want to use Hydra and add the following inside the file
project/plugins.sbt (if the file isn't there, create it):
resolvers += Resolver.url("Triplequote Plugins Releases", url("https://repo.triplequote.com/artifactory/sbt-plugins-release/"))(Resolver.ivyStylePatterns) addSbtPlugin("com.triplequote" % "sbt-hydra" % "2.0.0")
If sbt fails to resolve the Hydra artifacts please read this section for how to troubleshoot the problem.
If you're using Hydra on your developer machine, you need to activate a Hydra license before you can compile with Hydra. See the License section for how to do this on other build tools. Inside Sbt, type the following, using the actual license number you obtained:
> hydraActivateLicense XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX [info] Activating using https://activation.triplequote.com/algas/. This may take some time.. [info] License successfully activated
Compiling with Hydra¶
Now that Hydra is installed, let's check how it works. Enter the sbt shell and execute the
$ sbt [info] ... > compile [info] Compiling 80 Scala sources to ... [info] Using 4 Hydra workers to compile Scala sources. [info] Starting MetricsService in /home/john/.triplequote/metrics [success] ... >
When executing the
compile task you should notice the message
[info] Using 4 Hydra workers to compile Scala sources. (the number of workers may differ, as it depends on how many physical cores your machine has and how many Scala sources need to be compiled).
Congratulations, you have successfully installed Hydra!
While compiling your Scala source files, Hydra also collects compilation metrics that help you keep compile time under control. With the help of a modern web-based dashboard, you can track how compilation time evolves on your project, commit after commit. Even more importantly, you can prevent unexpected compile time deteriorations to land in the development branch before hampering everyone's productivity.
In the sbt output above you might have noticed the message
[info] Starting MetricsService in /home/john/.triplequote/metrics
This informs you that Hydra will try to push compilation metrics to a service that is expected to run on localhost (note that Hydra will work just fine also if you decide not to install the dashboard).
To set-up the dashboard please read the installation instruction.
Know your memory requirements¶
Hydra has slightly higher memory requirements than regular Scala, so make sure you keep an eye on the JVM behavior. If compiling your codebase using Hydra doesn't deliver the desired speed up, try to launch sbt with more memory:
$ sbt -mem 4096 [info] ...
If your project has a
.jvmopts file then the value passed to
-mem is ignored. In this case, simply increment the heap value (
-Xmx) declared in the
Also, see tuning memory for how to make the sbt memory configuration part of your project.
Benchmarking how Hydra performs on your project couldn't be easier. Simply enter the sbt shell and execute the
$ sbt [info] ... > hydraBenchmark 10 ... // Hold on, benchmark is running!
hydraBenchmark command will compare the performance of Hydra versus vanilla Scala for all projects in your build, producing a detailed report with the speedup delivered by Hydra. Read Benchmark for the glorious details on how the
hydraBenchmark command works.