Skip to content

Instantly share code, notes, and snippets.

@hykw
Last active December 29, 2015 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hykw/c4d338d7f95b0e00ad1f to your computer and use it in GitHub Desktop.
Save hykw/c4d338d7f95b0e00ad1f to your computer and use it in GitHub Desktop.
Phoenix:CentOS6.7にPhoenixを一からインストールして稼働させてみる

CentOSと書いていますが、直接依存するものは Erlang だけなので、他のバージョン、ディストリビューションでも同じだと思います。

手順および必要な物は Installation に書いてあるとおりそのままです。現時点では DBや static ファイルのコンパイルは行わないため、node.js などのインストールは行いません。

ところで Phoenix って単語、超打ちづらくありませんか? 何度も入力するのが辛くて、@p で Phoenix に変換できるように辞書登録してしまいました w

インストール手順

Erlang および Elixir は セオリー通りの方法でErlang(とElixir)をインストールなどの方法により、既にインストールされているものとします。

Hex

新規環境でない限りは既に入っているかと思いますが、もし無ければ mix local.hex しておきます(mix deps.get すれば勝手に入るでしょうが)。

$ mix hex.info
Hex v0.9.0

Phoenix

GitHub の Phoenix のリリースノート から ez ファイルを探します(zip の方じゃないので注意)。現時点では v1.1.0 が最新のようなので、これを入れます。

$ mix archive.install https://github.com/phoenixframework/phoenix/releases/download/v1.1.0/phoenix_new-1.1.0.ez

$ mix help|grep phoenix
mix phoenix.new       # Create a new Phoenix v1.1.0 application

inotify-tools

inotify-tools が入っていない場合、Phoenix 起動時に下記のような警告が表示されます。

[error] backend port not found: :inotifywait

https://github.com/rvoicilas/inotify-tools/wiki 記載の方法でインストールしておきます。

yum install inotify-tools

プロジェクトを作成して起動

sample_web というプロジェクトを作成してみます。Brunch.io は利用しないため、--no-brunch オプションを指定しています。依存ファイルのコンパイルが終わると、port:4000 で Phoenix が起動します。

$ mix phoenix.new sample_web --no-brunch

$ cd sample_web
$ mix phoenix.server

Endpoint は http://localhost:4000 と表示されていますが、接続元を localhost に制限しているようなことは無いので、外部に直接繋がっているサーバの場合、いきなり 4000 ポートで接続できます。

ベンチマーク

動作環境はサーバ側は さくらのVPS の 4GB で、クライアント側は 1GB のものを使っています。

同時接続数を増やした時に fd を使い切るため、クライアント側の ulimit -n は 10240 に上げてあります。

* hard nofile 10240
* soft nofile 10240

Phoenix はそのまま、PHP は wget http://localhost:4000/ して持ってきた HTML をヒアドキュメントで出力しています(下記参照)。

<?php

  echo <<<EOL
  <!DOCTYPE html>
  <html lang="en">
    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge">
      <meta name="viewport" content="width=device-width, initial-scale=1">



   </div> <!-- /container -->
      <script src="/js/app.js"></script>
    <iframe src="/phoenix/live_reload/frame" style="display: none;"></iframe>
  </body>
  </html>
  EOL;

ab でベンチマーク

-n は 10000 を指定しています。

| 同時接続数(-c) | PHP(Req) | Phoenix(Req) | PHP(Time) | Phoenix(Time) | 10 | 241 | 124 | 4.1 | 8.0 | 100 | 1404 | 834 | 0.7 | 1.1 | 200 | 1726 | 1178 | 0.5 | 0.8 | 300 | - | 1422 | - | 0.7 | 400 | - | 1633 | - | 0.6 | 500 | - | 1624 | - | 0.6 | 1000 | - | 1708 | - | 0.58

※凡例 Req = Requests per second(sec) Time = Time per request(ms)

複数サーバから ab を実行

* soft nofile 10240
* hard nofile 10240

ulimitを10240 に上げて、3台のVPSからアクセス

| 各同時接続数(-c) | Phoenix(Req) | Phoenix(Time) | 100 | 516 | 559 | 493 | 1.9 | 1.7 | 2.0 | 300 | 654 | 593 | 483 | 1.5 | 1.6 | 1.6 | 500 | 599 | 573 | 579 | 1.6 | 1.7 | 1.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment