Ruby Enterprise Editionを入れてみる
Passengerの開発元から「Ruby Enterprise Edition」が出たそうなので早速入れてみることにします。「Railsアプリのメモリ使用量が平均33%少なくなる」らしいし、安定していて速いということですから本当なら万々歳ですね。
インストール
手順は次の通り。エラーメッセージを含めた試行錯誤の経過は「だらだらしたインストール」の項をみてください。また、入替えた効果については「計測」の項をみてください。
→ http://www.rubyenterpriseedition.com/download.html から gzファイルをダウンロード $ tar xzvf ruby-enterprise-1.8.6-20080507.tar.gz $ s ./ruby-enterprise-1.8.6-20080507/installer $ e /etc/apache2/sites-available/my_site $ s /etc/init.d/apache2 restart
インストールは sudoでやってください。インストールがうまくいったら、表示された環境変数「RailsRuby」を apacheの設定ファイルに書いて、apacheを再起動すれば OKです。
だらだらとしたインストール
1.まず、ここ(→Download — Ruby Enterprise Edition)から gzファイルをダウンロードしてきます。今日落っことした時点では「ruby-enterprise-1.8.6-20080507.tar.gz」が最新バージョンのようです。
2.落っことした gzを適当なフォルダに突っ込みます。解凍するとき、フォルダを作ってその中にソースを解凍してくれますので、/tmp でも、/home/samba でもどこでもいいでしょう。そこで tarコマンドを使って解凍します。
$ tar xzvf ruby-enterprise-1.8.6-20080507.tar.gz ruby-enterprise-1.8.6-20080507/ ruby-enterprise-1.8.6-20080507/platform_info.rb ruby-enterprise-1.8.6-20080507/rubygems/ : : ruby-enterprise-1.8.6-20080507/source/time.c ruby-enterprise-1.8.6-20080507/runtime
3.では、インストーラを使ってインストールします。ここ(→Download — Ruby Enterprise Edition)には「./ruby-enterprise-X.X.X/install」と書いてありますが、installコマンドはありません。installer です。
$ ./ruby-enterprise-1.8.6-20080507/installer Welcome to the Ruby Enterprise Edition installer This installer will help you install Ruby Enterprise Edition 1.8.6-20080507. Don't worry, none of your system files will be touched if you don't want them to, so there is no risk that things will screw up. You can expect this from the installation process: 1. Ruby Enterprise Edition will be compiled and optimized for speed for this system. 2. Ruby on Rails will be installed for Ruby Enterprise Edition. 3. You will learn how to tell Phusion Passenger to use Ruby Enterprise Edition instead of regular Ruby. Press Enter to continue, or Ctrl-C to abort.
「変なことしないから心配しないでね。速くなるからね」ということでしょうか。ま、変なことされてもいいので、Enterを押してインストールします。
Checking for required software... * GNU C++ compiler... found at /usr/bin/g++ * Zlib development headers... found * OpenSSL development headers... found -------------------------------------------- Target directory Where would you like to install Ruby Enterprise Edition to? (All Ruby Enterprise Edition files will be put inside that directory.) [/opt/ruby-enterprise-1.8.6-20080507] : ← このままでいいので Enterを押します -------------------------------------------- Compiling and optimizing the memory allocator for Ruby Enterprise Edition In the mean time, feel free to grab a cup of coffee. ./configure --prefix=/opt/ruby-enterprise-1.8.6-20080507 --disable-dependency-tracking checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu : : mkdir -p /opt/ruby-enterprise-1.8.6-20080507/lib mkdir: cannot create directory `/opt/ruby-enterprise-1.8.6-20080507': Permission denied
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
やっぱり1回ではインストールできませんでした。sudo でやり直しです。
$ s ./ruby-enterprise-1.8.6-20080507/installer Welcome to the Ruby Enterprise Edition installer : : Press Enter to continue, or Ctrl-C to abort. ← Enterを押します Checking for required software... * GNU C++ compiler... found at /usr/bin/g++ * Zlib development headers... found * OpenSSL development headers... found -------------------------------------------- Target directory Where would you like to install Ruby Enterprise Edition to? (All Ruby Enterprise Edition files will be put inside that directory.) [/opt/ruby-enterprise-1.8.6-20080507] : ← このままでいいので Enterを押します -------------------------------------------- Compiling and optimizing the memory allocator for Ruby Enterprise Edition In the mean time, feel free to grab a cup of coffee. It looks like the source is already configured. Skipping configure script... make libtcmalloc_minimal.la make: `libtcmalloc_minimal.la' is up to date. : : -------------------------------------------- Ruby Enterprise Edition is successfully installed! If you're using Phusion Passenger (http://www.modrails.com), and you want it to use Ruby Enterprise Edition, then edit your Apache configuration file, and change the 'RailsRuby' option: RailsRuby /opt/ruby-enterprise-1.8.6-20080507/bin/ruby If you ever want to uninstall Ruby Enterprise Edition, simply remove this directory: /opt/ruby-enterprise-1.8.6-20080507 If you have any questions, feel free to visit our website: http://www.rubyenterpriseedition.com
4.インストール無事完了です。ここに書かれた「RailsRuby」を apacheの設定ファイルに追加します。
$ e /etc/apache2/sites-available/my_siteRailsRuby /opt/ruby-enterprise-1.8.6-20080507/bin/ruby RailsMaxPoolSize 10 RailsPoolIdleTime 300 : :
5.apacheを再起動します。
$ s /etc/init.d/apache2 restart
* Restarting web server apache2
...done.
リスタート OK、Railsアプリが動くことを確認しました。
計測
「Railsアプリのメモリ使用量が平均33%少なくなって、安定して速い」というのを確認してみます。まず、通常の「Ruby1.8.6」で動かしたときの状態から。
$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 16949 0.1 0.8 87512 6668 ? Ssl 06:34 0:00 /usr/sbin/apache2 -k start www-data 16954 0.0 0.4 38332 3648 ? S 06:34 0:00 /usr/sbin/apache2 -k start www-data 16955 0.0 0.5 38336 4228 ? S 06:34 0:00 /usr/sbin/apache2 -k start www-data 16956 0.0 0.4 38332 3648 ? S 06:34 0:00 /usr/sbin/apache2 -k start www-data 16959 0.0 0.4 38332 3648 ? S 06:34 0:00 /usr/sbin/apache2 -k start www-data 16960 0.0 0.4 38332 3648 ? S 06:34 0:00 /usr/sbin/apache2 -k start www-data 17046 0.0 0.4 79312 3720 ? S 06:34 0:00 /usr/sbin/apache2 -k start root 16950 1.6 0.7 17648 6192 ? Sl 06:34 0:00 Passenger spawn server root 17045 25.5 2.7 34624 21588 ? S 06:34 0:02 Passenger FrameworkSpawner: 2.0.2 xam 17048 7.1 2.7 34748 20984 ? S 06:34 0:00 Passenger ApplicationSpawner: /home/ww xam 17050 9.3 2.8 34912 21748 ? S 06:34 0:00 Rails: /home/www/2.5-55.jp
「Ruby Enterprise Edition」に切り替えたあとの状態はこちら。
$ ps aux 134mam:/home/www/2.5-55.ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 17151 0.2 0.8 87524 6680 ? Ssl 06:35 0:00 /usr/sbin/apache2 -k start www-data 17156 0.0 0.4 38344 3660 ? S 06:35 0:00 /usr/sbin/apache2 -k start www-data 17157 0.0 0.5 38348 4220 ? S 06:35 0:00 /usr/sbin/apache2 -k start www-data 17158 0.0 0.4 38344 3660 ? S 06:35 0:00 /usr/sbin/apache2 -k start www-data 17161 0.1 0.4 38344 3660 ? S 06:35 0:00 /usr/sbin/apache2 -k start www-data 17162 0.0 0.4 38344 3660 ? S 06:35 0:00 /usr/sbin/apache2 -k start www-data 17248 0.0 0.4 79324 3732 ? S 06:35 0:00 /usr/sbin/apache2 -k start root 17152 2.3 0.7 17648 6192 ? Sl 06:35 0:00 Passenger spawn server root 17247 29.5 2.7 34628 21588 ? S 06:35 0:02 Passenger FrameworkSpawner: 2.0.2 xam 17250 8.2 2.7 34752 20984 ? S 06:35 0:00 Passenger ApplicationSpawner: /home/ww xam 17252 8.8 2.7 34912 21712 ? S 06:35 0:00 Rails: /home/www/2.5-55.jp
うーん、ほとんど変わりません(切り替え後の Passenger FrameworkSpawnerと RailsがちょっとCPUを食ってるのは裏でやってることの違いじゃないかな)。測り方が悪いのか、重い処理を行っていないから効果がでていないのか、その辺よくわかりませんが、特に悪くなっているわけでもないので、しばらくはこれでいくことにします。
参考
- 「Ruby Enterprise Edition」が出たことは、こちら(→something new and exciting)で知りました。いつもありがとうございます。