Ruby on Rails effect on ARM

I was wondering if we can replace our Atom N270-based nettops that run Rails (ruby 1.8.6 ...) webapp with some equivalent ARM-based device (we like installation without a fan, power consumption, etc.) .

The ARM device was XScale-PXA270 @ 520, 128 MB (and possibly some slower SDRAMs), running under Linux, there was always enough free memory with comparable performance, like a jailbroken iPhone.

Benchmarking the production database (SQLite) gave us promising results (ARM was just 20-30% slower), so I tried to create a ruby ​​(1.9.2p0).

The rails application started up slowly on ARM (fetching from sql and generating templates 10-20x slower). I decided to run some tests to find bottlenecks.

Again, some of the results were fine (along with the old ruby ​​1.8.6, which we are using now, 6x slower than ruby ​​1.9.2), and some were very slow (20-30 times slower). Fe. ARM hash methods seem to be 40 times slower. The launch of the Ruby Benchmark Suite revealed more bottlenecks, strings, threads, arrays ...

I knew that ARM was slower than Atom, I just did not expect such a huge difference, especially after SQLite worked fine.

Is there a drawback with Ruby on ARM, do I need to apply some corrections, is it hopeless and should rewrite the entire application in C if I want to use an ARM device, or simply the device does not have enough processing power?

<strong> Examples

def fib(n) 
  return 1 if n < 2
  fib(n-1)+fib(n-2)
end 

Benchmark.bm do |x| 
  x.report { fib(32) }
  x.report { fib(36) }
  x.report { h = {}; (0..10**3).each {|i| h[i] = i}  } 
  x.report { h = {}; (0..10**4).each {|i| h[i] = i}  } 
  x.report { h = {}; (0..10**5).each {|i| h[i] = i}  } 
end
ruby -rbenchmark bench.rb

Atom N270, 1 GB

ruby 1.9.2p0 (2010-08-18) [i686-linux]
      user     system      total        real
  2.440000   0.000000   2.440000 (  2.459400)
 16.780000   0.030000  16.810000 ( 17.293015)
  0.000000   0.000000   0.000000 (  0.001180)
  0.020000   0.000000   0.020000 (  0.012180)
  0.160000   0.000000   0.160000 (  0.161803)

ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-linux]
      user     system      total        real
 12.500000   0.020000  12.520000 ( 12.628106)
 84.450000   0.170000  84.620000 ( 85.879380)
  0.010000   0.000000   0.010000 (  0.002216)
  0.040000   0.000000   0.040000 (  0.032939)
  0.240000   0.010000   0.250000 (  0.255756)

XScale-PXA270 @520, 128 ruby 1.9.2p0 (2010-08-18) [arm-linux]

      user     system      total        real
 12.470000   0.000000  12.470000 ( 12.526507)
 85.480000   0.000000  85.480000 ( 85.939294)
  0.060000   0.000000   0.060000 (  0.060643)
  0.640000   0.000000   0.640000 (  0.642136)
  6.460000   0.130000   6.590000 (  6.605553)

:

 ./configure --host=arm-linux --without-X11 --disable-largefile \
--enable-socket=yes --without-Win32API --disable-ipv6 \
--disable-install-doc --prefix=/opt --with-openssl-include=/opt/include/ \
--with-openssl-lib=/opt/include/lib

ENV:

PFX=arm-iwmmxt-linux-gnueabi

export DISCIMAGE="/opt"
export CROSS_COMPILE="arm-linux-"
export HOST="arm-linux"
export TARGET="arm-linux"
export CROSS_COMPILING=1
export CC=$PFX-gcc
export CFLAGS="-O3 -I/opt/include"
export LDFLAGS="-O3 -L/opt/lib/"
#LIBS=
#CPPFLAGS=
export CXX=$PFX-g++
#CXXFLAGS=
export CPP=$PFX-cpp

export OBJCOPY="$PFX-objcopy"
export LD="$PFX-ld"
export AR="$PFX-ar" 
export RANLIB="$PFX-ranlib"
export NM="$PFX-nm"
export STRIP="$PFX-strip"
export ac_cv_func_setpgrp_void=yes
export ac_cv_func_isinf=no
export ac_cv_func_isnan=no
export ac_cv_func_finite=no

+3
3

, , Ruby 1.9.2 ( 1.8.x) x86. Atom ARM Ruby 1.8.x. , , . , , Ruby 1.9.x:

Ruby 1.9.2 [...] Ruby Ruby VM (YARV)

, : " YARV x86? ARM-?"

+4

pi :

pi@raspberrypi:~$ uname -a
Linux raspberrypi 3.6.11+
pi@raspberrypi:~$ ruby -v
ruby 2.0.0p195 (2013-05-14 revision 40734) [armv6l-linux-eabihf]
pi@raspberrypi:~$ ruby benchmark.rb 
       user     system      total        real
   6.580000   0.000000   6.580000 (  6.585575)
  45.080000   0.000000  45.080000 ( 45.132900)
   0.000000   0.000000   0.000000 (  0.008709)
   0.090000   0.000000   0.090000 (  0.095851)
   1.040000   0.010000   1.050000 (  1.044347)

RP2 ( 2015 ):

pi@raschpi ~ $ uname -a
Linux raschpi 4.1.13-v7+ #826 SMP PREEMPT Fri Nov 13 20:19:03 GMT 2015 armv7l GNU/Linux
pi@raschpi ~ $ ruby -v
ruby 2.2.1p85 (2015-02-26 revision 49769) [armv7l-linux-eabihf]
pi@raschpi ~ $ ruby benchmark.rb 
       user     system      total        real
   4.450000   0.000000   4.450000 (  4.446841)
  30.460000   0.000000  30.460000 ( 30.473665)
   0.010000   0.000000   0.010000 (  0.002306)
   0.020000   0.000000   0.020000 (  0.023236)
   0.290000   0.000000   0.290000 (  0.292746)

RP3-B ( 2017 - Raspian Jessie):

pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l GNU/Linux
pi@raspberrypi:~ $ ruby -v
ruby 2.3.3p222 (2016-11-21) [arm-linux-gnueabihf]
pi@raspberrypi:~ $ ruby -rbenchmark benchmark.rb
       user     system      total        real
   4.030000   0.000000   4.030000 (  4.032046)
  30.940000   0.000000  30.940000 ( 30.943480)
   0.000000   0.000000   0.000000 (  0.001352)
   0.000000   0.010000   0.010000 (  0.013266)
   0.260000   0.000000   0.260000 (  0.251937)
+2

Using the code provided in the sample question, these are my results on a Raspberry Pi running on Raspbian with an armv6l processor:

uname -a
Linux ginger 3.1.9+ #168 PREEMPT Sat Jul 14 18:56:31 BST 2012 armv6l GNU/Linux

ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [armv6l-linux-eabi]

ruby benchmark.rb
   user     system      total        real
 7.810000   0.000000   7.810000 (  7.823737)
53.520000   0.010000  53.530000 ( 53.630399)
 0.010000   0.000000   0.010000 (  0.007818)
 0.090000   0.000000   0.090000 (  0.090667)
 0.950000   0.030000   0.980000 (  0.980731)
+1
source

Source: https://habr.com/ru/post/1771716/


All Articles