Recently we worked with a client where we had to run a part of their multi-threaded code in JRuby for performance reasons. They have been using CircleCI with MRI for running tests. In this post I will explain how we configured CircleCI to run the same tests using both JRuby and MRI.
circle.yml file for configuration. Before configuring JRuby, this is how it looked like:
Here are the steps to enable JRuby in CircleCI.
Specify the JDK version
We need to specify a JDK version before using JRuby.
Install proper dependencies
We needed to use JRuby 184.108.40.206 but the version of JRuby that came with Ubuntu 12.04 image of CircleCI was different. We added
rvm install command as follows to install specific version that we wanted. Also we can configure any script (like
bundle install) that needs to run before running tests.
rvm-exec to set JRuby for running tests for this particular component in the
test section. Otherwise by default it picks up MRI.
Improving test runs on JRuby
Once we started running tests with JRuby, we observed it was taking comparatively slower to finish all tests. Most of the time was spent in starting the JVM. We made it faster by setting
--dev parameter in
JRUBY_OPTS environment variable. This parameter improves JRuby boot time and it shaved more than a minute time for us.
Here is the final circle.yml file: