こんにちは! JQです。
前回は『 OSS編~Jubatusを試してみる①~ 』と題して、オンライン機械学習向けの分散処理フレームワークのJubatusを試してみました。
今回は『OSS編~Jubatusを試してみる②~』と題して、1台のインスタンス上でJubatusの分散処理を試してみたいと思います。
JubatusではZookeeperを利用して分散処理を行うことが出来ます。
Zookeeperとは
分散アプリケーションのためのパフォーマンスの高いコーディネーションサービスです。
Zookeeoer
1.Zookeeperインストール
先ずはZookeeperをインストールします。
Apache Zookeeperのサイトからダウンロードします。
1$ sudo wget http://ftp.kddilabs.jp/infosystems/apache/zookeeper/stable/zookeeper-3.4.6.tar.gz1$ tar xvzf zookeeper-3.4.6.tar.gzZookeeperではJavaを利用するため、インストールしておきます。
1$ sudo apt-get install openjdk-7-jre2.設定ファイルの作成
続いてZookeeperの設定ファイルを作成します。
サンプルファイルからコピーします。
1$ cp zookeeper-3.4.6/conf/zoo_sample.cfg zookeeper-3.4.6/conf/zoo.cfg中身は以下のようになります。
1# The number of milliseconds of each tick2tickTime=200034# The number of ticks that the initial56# synchronization phase can take78initLimit=10910# The number of ticks that can pass between1112# sending a request and getting an acknowledgement1314syncLimit=51516# the directory where the snapshot is stored.1718# do not use /tmp for storage, /tmp here is just1920# example sakes.2122dataDir=/tmp/zookeeper2324# the port at which the clients will connect2526clientPort=21812728# the maximum number of client connections.2930# increase this if you need to handle more clients3132#maxClientCnxns=6033#3435# Be sure to read the maintenance section of the3637# administrator guide before turning on autopurge.3839#4041# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance4243#4445# The number of snapshots to retain in dataDir4647#autopurge.snapRetainCount=34849# Purge task interval in hours5051# Set to "0" to disable auto purge feature5253#autopurge.purgeInterval=13.Zookeeperの起動
Zookeeperを起動します。
1$ /home/ubuntu/zookeeper-3.4.6/bin/zkServer.sh start2JMX enabled by default3Using config: /home/ubuntu/zookeeper-3.4.6/bin/../conf/zoo.cfg4Starting zookeeper ... STARTED4.Jubatusの設定ファイルをZookeeperに設定
続いてJubatusの設定ファイルをZookeeperに設定します。
1$ jubaconfig --cmd write --zookeeper=localhost:2181 --file shogun.json --name shogun --type classifier5.Jubatus Proxyの起動
Jubatus Proxyを起動します。
今回はclassifierのサンプルプログラムを利用するため、jubaclassifier_proxyで起動します。
1$ jubaclassifier_proxy --zookeeper=localhost:2181 --rpc-port=9198 &6.Jubatusサーバの起動
Jubatusサーバのプロセスを複数起動します。
–nameで同じクラスタとして扱います。
1$ jubaclassifier --rpc-port=9180 --name=shogun --zookeeper=localhost:2181 &2$ jubaclassifier --rpc-port=9181 --name=shogun --zookeeper=localhost:2181 &3$ jubaclassifier --rpc-port=9182 --name=shogun --zookeeper=localhost:2181 &確認してみます。
1$ sudo /home/ubuntu/zookeeper-3.4.6/bin/zkCli.sh -server localhost:21812[zk: localhost:2181(CONNECTED) 0] ls /jubatus/actors/classifier/shogun/nodes3[10.185.62.12_9181, 10.185.62.12_9182, 10.185.62.12_9180]7.プログラムの実行
今回はサンプルプログラムのShogunを利用しています。
クライアントプログラムのportをProxyのポートにnameをクラスタ名に修正して実行します。
1#!/usr/bin/env python23# coding: utf-845host = '127.0.0.1'6port = 91987name = 'shogun'89$ python shogun.py10徳川 慶喜11足利 義昭12北条 守時いかがでしたでしょうか?
次回は『OSS編~Jubatusを試してみる③~』と題して、Jubatusを複数台のインスタンスで分散処理を試してみたいと思います。
お楽しみに!!!