LoginSignup
2
2

More than 5 years have passed since last update.

Riakの環境を0からつくってみる ~Perl編~

Last updated at Posted at 2013-07-17

まっさらなCentOS 6.3でやっている想定で書いてます。

Install

以下のページより自分の環境用のInstall説明ページヘ飛ぶ
http://docs.basho.co.jp/riak/latest/tutorials/installation/

今回はCentOS

wget http://downloads.basho.com.s3-website-us-east-1.amazonaws.com/riak/CURRENT/rhel/6/riak-1.4.0-1.el6.x86_64.rpm
sudo rpm -Uvh riak-1.4.0-1.el6.x86_64.rpm

※残念ながらドキュメントに書いてあるVersionは違うので、現在の最新のVersionを指定する必要がある

起動

sudo riak start

とすると

!!!!
!!!! WARNING: ulimit -n is 1024; 4096 is the recommended minimum.
!!!!

怒られました。
警告なのでとりあえず使ってみる部分にはいいかもしれませんが、
修正してみましょう。

一時的な対策

ulimit -n 4096
sudo riak stop && sudo riak start

恒久的な対応

sudo vi /etc/security/limits.conf
sudo su -
ulimit -n
exit
sudo riak stop && sudo riak start

※自分で対応したあとに、ドキュメントにちゃんと対処方法が書いてあることに気づいたorz

これで怒られずに起動できるはずです。

通信できるかの確認は以下。

$ sudo riak ping
pong # pongとでればOK pangならNG

curlでも確認できます

curl -v http://127.0.0.1:8098/riak/test

たくさん情報が出ます。

Perlから使ってみる

myfinderさんがbenchスクリプトをあげてくださってます。

が、導入がめんどくさかったので端折りました。

Perlとcpanmのインストール(すでにしている人は飛ばしてください)

sudo yum install -y git
sudo yum install -y perl perl-devel
git clone git://github.com/tokuhirom/plenv.git ~/.plenv
echo 'export PATH="$HOME/.plenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(plenv init -)"' >> ~/.bash_profile
exec $SHELL -l
git clone git://github.com/tokuhirom/Perl-Build.git ~/.plenv/plugins/perl-build/
plenv install 5.18.0
plenv global 5.18.0
plenv install-cpanm

Riakが使える準備

cpanm Data::Riak Data::Riak::Fast Net::Riak

Benchmarkスクリプトを実行してみる

git clone https://gist.github.com/6020556.git
cd 6020556
perl bench.pl
perl bench2.pl
  • bench1
Data::Riak: 2.0
Data::Riak::Fast: 0.03
Net::Riak: 0.1702

                       Rate net-riak(PBC) net-riak(REST) data-riak(REST) data-riak-fast(REST)
net-riak(PBC)        58.9/s            --            -5%            -84%                 -94%
net-riak(REST)       62.1/s            5%             --            -83%                 -94%
data-riak(REST)       375/s          536%           503%              --                 -61%
data-riak-fast(REST)  971/s         1550%          1464%            159%                   --
  • bench2
Data::Riak: 2.0
Data::Riak::Fast: 0.03
Net::Riak: 0.1702
                      Rate net-riak(REST) data-riak(REST) net-riak(PBC) data-riak-fast(REST)
net-riak(REST)       415/s             --            -24%          -48%                 -56%
data-riak(REST)      543/s            31%              --          -32%                 -42%
net-riak(PBC)        800/s            93%             47%            --                 -15%
data-riak-fast(REST) 943/s           127%             74%           18%                   --

この中ではData::Riak::Fastが一番早いということがわかりました。
詳細はベンチマークスクリプトを御覧ください。

外部のサーバーから叩く場合

127.0.0.1しか受け付けてないので、全部のIPをOKにする
※本当はちゃんとIP指定したほうがいいです!!!

vi /etc/riak/app.config
-{pb,  [ {""127.0.0.1,  8087 } ]}
+{pb,  [ {"0.0.0.0",  8087 } ]}

-{http,  [ {"127.0.0.1",  8098 } ]}, 
+{http,  [ {"0.0.0.0",  8098 } ]}, 

-%{https,  [{ "127.0.0.1",  8098 }]}, 
+%{https,  [{ "0.0.0.0",  8098 }]}, 

まとめ

とりあえずこれでRaikの勉強をしていけそうです。

参考URL

Riakのドキュメント
Riakの薄い本
Data::Riak(CPAN)

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2