Speed up JRuby + Rails startup time

first check – https://github.com/jruby/jruby/wiki/Improving-startup-time

Set JRUBY_OPTS for development

~/.rvm/hooks/after_use_jruby_opts
#!/usr/bin/env bash

. "${rvm_path}/scripts/functions/hooks/jruby"

export PROJECT_JRUBY_OPTS="-Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -Xcompile.mode=OFF"

if [[ "${rvm_ruby_string}" =~ "jruby" ]]
then
jruby_options_append "${PROJECT_JRUBY_OPTS[@]}"
else
jruby_options_remove "${PROJECT_JRUBY_OPTS[@]}"
jruby_clean_project_options
fi

One by one

-Xcompile.invokedynamic=false optimizations on bytecode instruction level dynamically.

-J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 same effect as client mode on 64bit JVM.

-J-noverify not verifying

-Xcompile.mode=OFF don’t do JIT

Nailgun

“Insanely Fast Java”
Preloads a JVM.

Not that much gain < 1 second

cd ~/.rvm/rubies/jruby-1.7.4/tool/nailgun
./configure
make install
$ time ruby bin/thor list
real 0m1.919s

$ ruby --ng-server &
NGServer started on all interfaces, port 2113.

$ time ruby --ng bin/thor list
real 0m1.331s

Drip

Charles Nutter @headius Nov 20 2012 “Big JRuby startup time improvements using Drip…give it a shot, let us know how it works: https://github.com/flatland/drip&#8221;

export JAVACMD=`which drip`
export DRIP_INIT_CLASS=org.jruby.main.DripMain

dripmain.rb
# org.jruby.main.DripMain
public static final String JRUBY_DRIP_PREBOOT_FILE = "./dripmain.rb";

Unfortunately buggy – https://github.com/flatland/drip/issues/51

All together

BEFORE LAZY REQUIRE (Bundler.require)
$ time ruby bin/rspec spec/models/tag_spec.rb
saved about ~3 secs.

DEFAULT
$ time ruby bin/rspec spec/models/tag_spec.rb

real 0m23.325s

JRUBY_OPTS

$ export JRUBY_OPTS="-Xcompile.invokedynamic=false -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -Xcompile.mode=OFF"
$ time ruby bin/rspec spec/models/tag_spec.rb

real 0m10.726s

JRUBY_OPTS + NAILGUN + SPORK

$ ruby --ng-server &
$ ruby --ng bin/spork
$ time ruby --ng bin/rspec spec/models/tag_spec.rb

real 0m3.453s

Auto enable Nailgun

~/.rvm/hooks/after_use_jruby

#!/usr/bin/env bash

\. "${rvm_path}/scripts/functions/hooks/jruby"

if [[ "${rvm_ruby_string}" =~ "jruby" ]]
then
jruby_ngserver_start
jruby_options_append "--ng" "${PROJECT_JRUBY_OPTS[@]}"
else
jruby_options_remove "--ng" "${PROJECT_JRUBY_OPTS[@]}"
jruby_clean_project_options
fi

Prefer binstub over bundle exec

bundle binstub rspec-core

bundle exec requires the executable script and call exec to replace the process. From the wiki “Avoid spawning sub-rubies”.

RailsRumble – StillAlive.com – website monitoring with cucumber syntax

I haven’t blogged for a while, I’ve been writing some notes in Facebook instead and I’ll move some of that back onto my blog later.
I’ve been doing alot of things this year as I always get myself into. Just last weekend I did this 48hrs RailsRumble with 3 other guys in Sydney. We’ve done pretty well considering it’s the first time we worked together, and pretty much just came together on forming a team for the rumble.

This was actually our first idea. Wouldn’t it be cool to use your cucumber test on your live site? Most site monitoring services out there only supports ping or at best some simple text find verification. How do you know your api is authenticating? How can you make sure your search engine daemon is still serving up results while you’re asleep. Ping cannot guarantee the integrity of your website anymore. So we have a solution, our entry – StillAlive, is a new way of monitoring your website. When “Status 200” is not OK, StillAlive lets you use simple English language (cucumber’s gherkin syntax) to interact with your webapps in order to make sure every feature of the site is working.

You can do things like:

When I go to http://tellthemwhen.com/
And I follow “Make a Time!”
Then I should see “Create Notification”
When I fill in “Time” with “Tomorrow”
And I fill in “Title” with “Test Notification”
And I fill in “Message” with “This is the message in the notification”
And I press “Create Notification”
Then I should see “Test Notification”
And I should see “This is the message in the notification”

We’ve gotten pretty good feedbacks so far from users and expert judges. We’ve already made plans to take this forward and make this into an awesome product. Let us know if you’ve anyway suggestions.

There’s only a few Other teams from Australia, they produced pretty cool stuff too.

HereTil by http://railsrumble.com/teams/rocket26
Desks Near Me by
http://railsrumble.com/teams/the-rad-warlike-annex

RedCity by http://railsrumble.com/teams/red-city-crew

There’s also two teams from Hong Kong which I thought did pretty well.

http://kookiebox.r10.railsrumble.com

http://newsprank.r10.railsrumble.com

You can soon vote for us here: Team- The Wizard of Oz

Hong Kong Ruby on Rails User Group for 2009

Hong Kong Ruby on Rails User Group

HK ROR user group deserves some long waited actions. I think there’s enough critical mass in Hong Kong now, and there’s definitely a community. The old google group was disappeared without much given reasons, but we’ve formed a new one. http://groups.google.com/group/hkror

Please sign up again and follow the new blog http://rubyonrailshk.com.

Also let me know if you’d like to help organise or contribute as a speaker in upcoming meetup events.

Open Source Freelancer Job Board

I registered osfreelancer.com at the time I registered railsjob.com, but I haven’t done anything to it for years. It is now pointing to a Jobamatic account. They are quite a good service I must say. Let’s see how much jobs I’ll get on that site. I might considered transforming railsjob into a similar service.