Skip to content

Instantly share code, notes, and snippets.

@rwjblue rwjblue/readme.md
Last active May 13, 2016

Embed
What would you like to do?
Guide to using drip with JRuby

#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
# mri ruby-1.9.3p327 with falcon patch and optimized for my arch (CFLAGS="-march=nocona -O3 -pipe")
\time -p rake environment > /dev/null
real 3.39
user 2.17
sys 0.69
# standard jruby-1.7.2 (no drip)
\time -p rake environment > /dev/null
real 12.96
user 27.92
sys 2.00
# jruby-1.7.2 with drip first run (no custom dripmain.rb)
\time -p rake environment > /dev/null
real 12.80
user 27.14
sys 2.00
# jruby-1.7.2 with drip subsequent runs (no custom dripmain.rb)
\time -p rake environment > /dev/null
real 12.25
user 0.06
sys 0.07
# jruby-1.7.2 with drip first run (dripmain.rb: "require_relative 'config/application'")
\time -p rake environment > /dev/null
real 8.78
user 11.98
sys 1.48
# jruby-1.7.2 with drip subsequent runs (dripmain.rb: "require_relative 'config/application'")
\time -p rake environment > /dev/null
real 1.71
user 0.06
sys 0.06
@Altonymous

This comment has been minimized.

Copy link

Altonymous commented Jan 22, 2013

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.

@Altonymous

This comment has been minimized.

Copy link

Altonymous commented Jan 23, 2013

After investigating further, it appears drip is launching a new process with every run. Thus defeating its purpose. I have yet to find a fix for this issue.

@alepulver

This comment has been minimized.

Copy link

alepulver commented May 2, 2013

I'm having the same problem, with identical times.

@doxavore

This comment has been minimized.

Copy link

doxavore commented Jun 25, 2013

I've also not had luck getting Drip to run, on Ubuntu 12.10 and OS X 10.8. Not much progress has been made on this issue since it was reported - I haven't had any luck in tracking it down myself. https://github.com/flatland/drip/issues/51

@thoughtchad

This comment has been minimized.

Copy link

thoughtchad commented Sep 4, 2013

Has anyone tried the "-Xlaunch.inproc=true" option? May be related to: https://jira.codehaus.org/browse/JRUBY-6788

@alexfalkowski

This comment has been minimized.

Copy link

alexfalkowski commented Feb 21, 2014

Does this even work?

@swistaczek

This comment has been minimized.

Copy link

swistaczek commented Mar 8, 2014

Any one successfull with Drip and TorqueBox?

@queuebit

This comment has been minimized.

Copy link

queuebit commented Mar 14, 2014

Thanks for all the troubleshooting others were doing.

I seemed to have solved the problem by setting export DRIP_INIT="" # Needs to be non-null for drip to use it at all!, see my stackoverflow post.

@aviflax

This comment has been minimized.

Copy link

aviflax commented May 13, 2016

This is excellent! Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.