
Looking at Ruby Inside today, I stumbled upon the article Justin Kulesza.
Is Your Application Running with Ruby - Slow? . Article from November 6, but on Habré about this situation not a word. 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 became as if slower. At first they made mistakes on iron, but quickly found out that the matter was in RVM, namely, that RVM does not use optimization at all when compiling.
Diagnosing a 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” execution time 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
CFLAGS must contain -O3.
I checked on my server - and the truth is, the problem is taking place.
')
The article provides the following 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, currently it is still easier:
$ rvm get head && rvm reinstall your.ruby.version
And besides, in the 'head'-version of RVM, there is a bad
patch from
funny-falcon available for the latest version of Ruby - 1.9.3-p327, which makes Ruby even faster (especially when downloading an application). 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.