
Ruby on your server can run 2 times slower due to RVM

Looking through Ruby Inside today, I came across an article by Justin Kulesza Is Your Application Running with Ruby - Slow? . Article of November 6, but not a word about this situation on Habré. And the essence of the article is this: the guys transferred their application from the server to Solaris to the server from Ubuntu and used RVM to compile Ruby. However, after the transfer, they noticed that the application seemed to be slower. At first they sinned on hardware, but quickly found out that the thing was RVM, namely, that RVM does not use optimization at all when compiling.
Diagnosing the problem is very simple:
$ time ruby -e "count = 0; while(count < 100000000); count = count + 1; end; puts count"
100000000
real 0m9.019s
user 0m8.933s
sys 0m0.016s
The “normal” runtime should be no higher than ~ 4 seconds.
Plus, the lack of optimization flags in ~ / .rvm / log / your.ruby.version / make.log :
CC = gcc
LD = ld
LDSHARED = gcc -shared
CFLAGS = -I/home/user/.rvm/usr/include -fPIC
XCFLAGS = -include ruby/config.h -include ruby/missing.h -fvisibility=hidden -DRUBY_EXPORT
CPPFLAGS = -I. -I.ext/include/x86_64-linux -I./include -I.
DLDFLAGS = -Wl,-soname,libruby.so.1.9
SOLIBS = -lpthread -lrt -ldl -lcrypt -lm
-O3 must be present in CFLAGS.
Checked on his server - and indeed, the problem has a place to be.
The article provides such a solution:
$ echo "rvm_configure_env=(CFLAGS=-O3)" > ~/.rvmrc
An alternative from this article :
$ echo 'rvm_configure_env=(CFLAGS="-march=native -O2")' > ~/.rvmrc
And then:
$ rvm reinstall your.ruby.version
However, for now it’s still easier:
$ rvm get head && rvm reinstall your.ruby.version
And besides, the notorious patch from funny-falcon for the latest version of Ruby - 1.9.3-p327, which makes Ruby even faster (especially when loading the application), is available in the 'head'-version of RVM . Installation is also simple:
$ rvm install 1.9.3 -n perf --patch falcon
$ rvm use 1.9.3-perf --default
After reinstallation, the server showed a speed increase of more than 2 times:
$ time ruby -e "count = 0; while(count < 100000000); count = count + 1; end; puts count"
100000000
real 0m4.117s
user 0m4.032s
sys 0m0.012s
So check your servers, speed up your applications.