ローリングコンバットピッチなう!

AIとか仮想化とかペーパークラフトとか

Jubatus勉強開始(JubatusをDocker環境で使う)

[technology]【メモ】Docker環境でのJubatus実行

Jubatusの勉強をしたいと思い、Ubuntu 18.04.1 LTSのサーバー環境(KVM guestです)にインストールを試みたのですが上手く行きません。

http://jubat.us/ja/quickstart.html
上記のクイックスタートページの通りに/etc/apt/sources.list.d/jubatus.listにaptのリポジトリを登録し、apt-getを実行するのですが、以下の様にlibopencv-features2d3.2がインストール出来ないと言われてしまいます。このパッケージだけどこかから引っ張ってこれないか?と思ったのですが適切なパッケージが見つからず。

toy@ubuntu01:~/jubatus_test/jubatus-tutorial-python$ sudo apt-get install jubatus
[sudo] password for toy: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 jubatus : Depends: libopencv-features2d3.2 but it is not installable
E: Unable to correct problems, you have held broken packages.toy@ubuntu01:~/jubatus_test/jubatus-tutorial-python$ sudo apt-get install jubatus
[sudo] password for toy: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 jubatus : Depends: libopencv-features2d3.2 but it is not installable
E: Unable to correct problems, you have held broken packages.

仕方がないので、docker imageを使うことにしました。こちらはクイックスタートページに記載の通り、

$ docker pull jubatus/jubatus

だけでインストール出来ました。

また

$ docker run --expose 9199 jubatus/jubatus jubaclassifier -f /opt/jubatus/share/jubatus/example/config/classifier/pa.json

で、サンプルの設定ファイルからjubatusの起動も簡単に出来ます。

さて、次に下記のBASICチュートリアルをとりあえずそのまま走らせようとしたのですが、ここでも問題が。
http://jubat.us/ja/tutorial/tutorial.html
チュートリアル通りにまず、チュートリアルプログラムとデータセットをダウンロードして展開するまではまあ普通に進みます。

  • 問題1:docker環境の外にあるコンフィグjsonファイルを指定してjubatusを起動する方法が判らない

    クイックスタートページのサンプルではdocker環境内部にあるjsonファイルを指定してjubatusを起動しています。
    チュートリアルでは

    $ jubaclassifier --configpath config.json

    と記載されており、Dockerイメージを使った場合の起動方法が書いてありません。Docker自体も使い始めたばかりで良くわからないなと思っていたら下記のjubatus blogにヒントがありました。
    blog.jubat.us
    docker runコマンドに-vオプションを付けるとdocker環境外のファイルパスをdocker環境にマウント出来る様です。dockerバリバリ使っている人には当たり前の話なんでしょうが、一昨日から使い始めたばかりという初心者はこんなところでも躓き。とりあえず、なるほどと思ってやってみたらまたエラー。

    toy@ubuntu01:~$ docker run --expose 9199 -v .:/tmp/config jubatus/jubatus jubaclassifier -f /tmp/config/config.json
    docker: Error response from daemon: create .: volume name is too short, names should be at least two alphanumeric characters.
    See 'docker run --help'.
    • vオプションに'.'表記でカレントディレクトリの指定は出来ない様です。
    $ docker run --expose 9199 -v $PWD:/tmp/config jubatus/jubatus jubaclassifier -f /tmp/config/config.json

    これでカレントディレクトリにあるconfig.jsonをdocker内のjubatusに渡せました。

  • 問題2: クライアント側のpython scriptを起動しても、jubatusに繋がらない

    ダウンロードしたチュートリアルプログラムtutorial.pyをBASICチュートリアル通りに起動すると以下の状況に。

    (py37) toy@ubuntu01:~/jubatus_test/jubatus-tutorial-python$ python tutorial.py
    --- Configuration ----------
    WARNING:tornado.general:Connect error on fd 9: ECONNREFUSED
    WARNING:tornado.general:Connect error on fd 9: ECONNREFUSED
    WARNING:tornado.general:Connect error on fd 9: ECONNREFUSED
    WARNING:tornado.general:Connect error on fd 9: ECONNREFUSED
    WARNING:tornado.general:Connect error on fd 9: ECONNREFUSED
    Traceback (most recent call last):
      File "tutorial.py", line 47, in <module>
        print(classifier.get_config())
      File "/home/toy/anaconda3/envs/py37/lib/python3.7/site-packages/jubatus/common/client.py", line 85, in get_config
        return self.jubatus_client.call("get_config", [], TString(), [])
      File "/home/toy/anaconda3/envs/py37/lib/python3.7/site-packages/jubatus/common/client.py", line 38, in call
        ret = future.get()
      File "/home/toy/anaconda3/envs/py37/lib/python3.7/site-packages/msgpackrpc/future.py", line 40, in get
        self._error_handler(self._error)
      File "/home/toy/anaconda3/envs/py37/lib/python3.7/site-packages/jubatus/common/client.py", line 18, in error_handler
        raise msgpackrpc.error.RPCError(e)
    msgpackrpc.error.RPCError: Retry connection over the limit
    

    これはチュートリアルプログラムのソースと、docker runコマンドでjubatusを起動した時の表示を良く読むと理由が分かりました。
    チュートリアルプログラムの先頭: デフォルトで127.0.0.1:9199につなぐ様になっている。

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    from __future__ import print_function
    
    import sys,json
    
    from jubatus.classifier.client import Classifier
    from jubatus.classifier.types import LabeledDatum
    from jubatus.common import Datum
    
    def parse_args():
        from optparse import OptionParser, OptionValueError
        p = OptionParser()
        p.add_option('-s', '--server_ip', action='store',
                     dest='server_ip', type='string', default='127.0.0.1')
        p.add_option('-p', '--server_port', action='store',
                     dest='server_port', type='int', default='9199')
        p.add_option('-n', '--name', action='store',
                     dest='name', type='string', default='tutorial')
        return p.parse_args()

    dockerでのjubatus起動時の表示: Private IPアドレス 172.17.0.2が付与されている。

    toy@ubuntu01:~/jubatus_test/jubatus-tutorial-python$ docker run --expose 9199 -v $PWD:/tmp/config jubatus/jubatus jubaclassifier -f /tmp/config/config.json
    2018-11-15 14:06:20,110 1 INFO  [server_util.cpp:429] starting jubaclassifier 1.1.0 RPC server at 172.17.0.2:9199

    ということで、

    $ python tutorial.py --server_ip 172.17.0.2

    で良さそうです。これで実行したところ、チュートリアルプログラムがdocker上のjubatusに繋がり、無事に動作しました。

とりあえず動く様になったので、チュートリアルプログラムの内容、データの内容をじっくり読み解いて理解に移りたいと思います。