Search code examples
jrubyjrubyonrails

How can I make drip use existing vm with dripmain.rb for rails app?


I am attempting to use drip to reduce JRuby VM startup time for a Rails app, per the JRuby wiki.

I see some speed up by changing some of the JRUBY_OPTS but I am not seeing any reduction using drip. It seems to be spinning up a new process/vm for each call instead of re-using the existing VM.

I was following this guide to get things setup.

dripmain.rb

require_relative './config/application'

terminal

$ { time ( jruby -e 'puts 9*9') }
81
( jruby -e 'puts 9*9'; )  0.08s user 0.08s system 14% cpu 1.144 total

$ drip ps
31166 org.flatland.drip.Main org.jruby.Main ...

$ { time ( jruby -e 'puts 9*9') }
81
( jruby -e 'puts 9*9'; )  0.08s user 0.08s system 13% cpu 1.182 total

$ drip ps
30965 org.flatland.drip.Main org.jruby.Main

I expected those process ids for drip to be the same. Open to hearing non-drip solutions as well. I looked into theine / nailgun but couldn't get them working either.


Solution

  • The problem was that I was missing this export:

    export DRIP_INIT="" # Needs to be non-null for drip to use it at all!

    Solution found as part of rvm shell script on github.

    # Source this file if you use Drip to make the JVM not suck
    # drip: https://github.com/flatland/drip
    # https://github.com/flatland/drip/wiki/JRuby
    
    # JAVACMD is honored by jruby
    export JAVACMD=`which drip`
    # Drip preloads our codez
    export DRIP_INIT_CLASS=org.jruby.main.DripMain
    export DRIP_INIT="" # Needs to be non-null for drip to use it at all!
    
    # settings from: https://github.com/jruby/jruby/wiki/Improving-startup-time
    export JRUBY_OPTS="-J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -X-C"