#Overview drip is an awesome command line tool that can be used to dramatically lower perceived JVM startup time. It does this by preloading an entirely new JVM process\instance and allowing you to simply use the preloaded environment. This has extraordinary results with jruby.
We reduced time to run rake environment
from 13 seconds to a mere 3.5 seconds. This is actually at or near MRI 1.9.3p327 (with falcon patch) speeds!
Adding a few addition jruby options will reduce startup time even further (down to 1.69 seconds).
#Install Drip Install drip if you haven't already (see https://github.com/flatland/drip)
brew update && brew install drip
#Environment Setup
jruby uses the JAVACMD environment variable (if present) as it's executable (usually which java
).
drip uses the DRIP_INIT_CLASS environment variable to determine the main class to load. jruby has a native java class already setup for this purpose: orb.jruby.main.DripMain.
export JAVACMD=`which drip`
export DRIP_INIT_CLASS=org.jruby.main.DripMain
#Project Setup Put any project specific initialization code (ruby code) in PROJECT_ROOT/dripmain.rb. This file is automatically called by the special org.jruby.main.DripMain class when intializing the standby JVM process.
# rails project:
require_relative 'config/application'
# non-rails bundler controlled project
require 'bundler/setup'
Bundler.require
#rvm integration If you would like to use drip automatically whenever you switch to jruby with rvm you will need to add a new hook file at $rvm_path/hooks/after_use_jruby_drip with the following content:
#!/usr/bin/env bash
if [[ "${rvm_ruby_string}" =~ "jruby" ]]
then
export JAVACMD=`which drip`
export DRIP_INIT_CLASS=org.jruby.main.DripMain
# settings from: https://github.com/jruby/jruby/wiki/Improving-startup-time
export JRUBY_OPTS="-J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify"
fi
Then you'll need to make that file executable:
chmod +x $rvm_path/hooks/after_use_jruby_drip
My benchmark results: https://gist.github.com/4591719
The only thing that seemed to make a difference for me was the JRUBY_OPTS
My dripmain.rb is just the rails implementation above.