Skip to content

Instantly share code, notes, and snippets.

@the8472
Created December 12, 2012 16:28
Show Gist options
  • Save the8472/4269272 to your computer and use it in GitHub Desktop.
Save the8472/4269272 to your computer and use it in GitHub Desktop.
Rails startup performance tuning with jruby. Note that those settings are *not* for optimal steady state operation.
### ruby 1.9.3 + railsexpress patches + GC tuning + -march=native -O3
time ruby script/rails r 'Post.count'
real 0m1.008s
user 0m0.820s
sys 0m0.180s
### jruby 1.7.2-dev 2012-12-12 + java 64bit 1.8.0-ea-b67 hotspot 25.0-b11
time jruby script/rails r 'Post.count'
real 0m15.269s
user 0m50.619s
sys 0m9.485s
time jruby -J-client script/rails r 'Post.count'
real 0m15.004s
user 0m48.283s
sys 0m10.433s
time jruby -J-server -J-XX:+UseCompressedOops -J-noverify -J-XX:+UseParallelOldGC script/rails r 'Post.count'
real 0m14.593s
user 0m49.111s
sys 0m8.777s
time jruby -J-server -J-XX:+UseCompressedOops -J-noverify -J-XX:+UseParallelOldGC -X-C script/rails r 'Post.count'
real 0m9.425s
user 0m27.438s
sys 0m6.236s
time jruby -J-server -J-XX:+UseCompressedOops -J-noverify -J-XX:+UseParallelOldGC -X-C -J-XX:+TieredCompilation -J-XX:+AggressiveOpts script/rails r 'Post.count'
real 0m9.754s
user 0m29.014s
sys 0m6.616s
time jruby -J-server -J-XX:+UseCompressedOops -J-noverify -J-XX:+UseParallelOldGC -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-XX:+AggressiveOpts -J-Xms500m -J-Xmx1024m -J-XX:NewSize=200m -J-Djruby.jit.threshold=500 -J-XX:CICompilerCount=3 script/rails r 'Post.count'
real 0m8.568s
user 0m7.492s
sys 0m6.956s
time jruby -J-server -J-XX:+UseCompressedOops -J-noverify -J-XX:+UseParallelOldGC -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -X-C -J-XX:CICompilerCount=3 script/rails r 'Post.count'
real 0m7.804s
user 0m7.320s
sys 0m6.824s
### new versions:
### jruby 1.7.2-dev 2012-12-19 + java 64bit 1.8.0-ea-b68 hotspot 25.0-b12
time jruby -Xcompile.invokedynamic=false -J-server -J-XX:+UseCompressedOops -J-noverify -J-XX:+UseParallelOldGC -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-XX:+AggressiveOpts -J-Xms500m -J-Xmx1024m -J-XX:NewSize=200m -J-Djruby.jit.threshold=500 -J-XX:CICompilerCount=3 script/rails r 'Post.count'
real 0m7.272s
user 0m6.852s
sys 0m5.964s
### WIN!
### we can get practically the same startup performance with -X-C and -X+C now. So jruby JIT = yes, java JIT = client mode equivalent.
### jruby 1.7.2-dev 2012-12-12 + java 32bit 1.8.0-ea-b67 hotspot 25.0-b11
time jruby -J-client -J-noverify -J-XX:+UseParallelOldGC -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -X-C -J-XX:CICompilerCount=3 script/rails r 'Post.count'
real 0m8.159s
user 0m8.769s
sys 0m8.057s
time jruby -J-server -J-noverify -J-XX:+UseParallelOldGC -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -X-C -J-XX:CICompilerCount=3 script/rails r 'Post.count'
real 0m6.898s
user 0m5.856s
sys 0m5.136s
* real-world app
* running in production mode
* minimalistic test data in the mysql running on this machine
* for the purpose of this test: no jrubrc, JAVA_OPTS or JRUBY_OPTS
* jruby 1.7.2.dev (1.9.3p327) 2012-12-19
* java 64bit build 1.8.0-ea-b68
* hotspot 25.0-b12
* rails 3.2.9
# these java flags are what's minimally necessary to get the app to run.
# bundler blows through the stack size otherwise; compressedoops + new meta space = GC problems
time jruby -J-Xss8m -J-Xmx1024m -J-XX:-UseCompressedOops script/rails r 'Rails.application.eager_load!; Account.count'
real 2m24.110s
user 4m43.182s
sys 0m20.913s
# tuned
time jruby -Xcompile.invokedynamic=false -J-server -J-XX:+UseCompressedOops -J-noverify -J-XX:+UseParallelOldGC -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-XX:+AggressiveOpts -J-Xms500m -J-Xmx1024m -J-XX:NewSize=200m -J-Djruby.jit.threshold=500 -J-XX:CICompilerCount=3 script/rails r 'Rails.application.eager_load!; Account.count'
real 0m29.614s
user 0m38.602s
sys 0m5.572s
### comparison with MRI
* 1.9.3p327
* railsexpress patchset (includes falcon patches)
* ruby and gems compiled with -O3 -march=native
* following GC settings used
RUBY_HEAP_MIN_SLOTS=5000000
RUBY_GC_MALLOC_LIMIT=100000000
RUBY_HEAP_SLOTS_INCREMENT=500000
RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
time ruby script/rails r 'Rails.application.eager_load!; Account.count'
real 0m7.996s
user 0m6.652s
sys 0m1.280s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment