Phalcon PHPとSails Node.jsのベンチマーク

(Last Updated On: 2018年8月13日)

以前にフレームワーク対決:Node.js+SailsとPHP+PhalconのベンチマークとしてPhalconとSailsのベンチマークを行ったのですが、Apacheを利用した場合のPhalconの性能が全く違うので取り敢えずブログに書きます。

このエントリはPhalcon Adventカレンダー17日目として書きました。少し前に設定がおかしいことに気づいて非公開にしていた物を修正しています。

Phalcon PHPのベンチマーク

Apache 2.4 + PHP 5.5 + Phalcon 2.0をフレームワーク対決:Node.js+SailsとPHP+Phalconのベンチマークを書いた時と同じPC(Intel Core i7 4770S – 4 core / 8 thread、Fedora20 x86_64)でベンチマークを取得しました。

ベンチマークの違い

  • 前回
    • Phalcon 1.xとPHPビルトインWebサーバー
    • Sails プロセスマネージャー無し
  • 今回
    • Phalcon 2.0、Apache httpd  2.4(Fedora20のパッケージデフォルト設定、.htaccessのみ有効化)
    • SailsとPM2

前回はPHPのビルトインWebサーバーだったのでCPUコアを一つしか使いませんでしたが、今回はApache httpdなので4コア/8スレッドすべてを使うことになります。

Sailsも全てのコア+ハイパースレッドを利用しないと公平なベンチマークとは言えないのでPM2を使って、全コア、全スレッドを使えるようにしています。

ベンチマークしたページは”phalcon project phalcontest”と”phalcon project phalconmicrotest –type=micro”として新しく作ったプロジェクトをそのまま使いました。

Phalcon Simple:
Requests per second: 11737.06 [#/sec] (mean)
100% 3 (longest request)

[yohgaki@dev html]$ ab -c 10 -n 20000 http://192.168.100.50/phalcontest/public/
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.100.50 (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests


Server Software:        Apache/2.4.10
Server Hostname:        192.168.100.50
Server Port:            80

Document Path:          /phalcontest/public/
Document Length:        204 bytes

Concurrency Level:      10
Time taken for tests:   1.704 seconds
Complete requests:      20000
Failed requests:        0
Total transferred:      9220000 bytes
HTML transferred:       4080000 bytes
Requests per second:    11737.06 [#/sec] (mean)
Time per request:       0.852 [ms] (mean)
Time per request:       0.085 [ms] (mean, across all concurrent requests)
Transfer rate:          5283.97 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     0    1   0.1      1       3
Waiting:        0    1   0.1      1       3
Total:          0    1   0.1      1       3

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      1
 100%      3 (longest request)

Phalcon Micro :
Requests per second: 16720.24 [#/sec] (mean)
100% 14 (longest request)

[yohgaki@dev html]$ ab -c 10 -n 20000 http://192.168.100.50/phalconmicrotest/public/
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.100.50 (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests


Server Software:        Apache/2.4.10
Server Hostname:        192.168.100.50
Server Port:            80

Document Path:          /phalconmicrotest/public/
Document Length:        261 bytes

Concurrency Level:      10
Time taken for tests:   1.196 seconds
Complete requests:      20000
Failed requests:        0
Total transferred:      10360000 bytes
HTML transferred:       5220000 bytes
Requests per second:    16720.24 [#/sec] (mean)
Time per request:       0.598 [ms] (mean)
Time per request:       0.060 [ms] (mean, across all concurrent requests)
Transfer rate:          8458.09 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:     0    1   0.1      1      13
Waiting:        0    1   0.1      0      13
Total:          0    1   0.1      1      14
ERROR: The median and mean for the waiting time are more than twice the standard
       deviation apart. These results are NOT reliable.

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      1
 100%     14 (longest request)

 

Simpleでも1万1千リクエスト/秒、Microは1万6千リクエスト/秒を超た性能です。

昨日、全てのコアを使ったSailsのベンチマーク結果を取得しました。スクリプト系言語のフレームワークとしてはかなり高速です。

Sails (8 threads/4 cores)
 Requests per second: 1774.98 [#/sec] (mean)

しかし、結果は一目瞭然です。速度目的でNode.jsのSailsを利用する意味はありません。

Phalcon Simple:
 Requests per second: 11737.06 [#/sec] (mean)
 100% 3 (longest request)

Phalcon Micro :
 Requests per second: 16720.24 [#/sec] (mean)
 100% 14 (longest request)

文字通りPhalconの方が「桁違いに速い」結果となりました。 

 

まとめ

前回のベンチマークの時、Phalconの分が遅いな、とは感じていたのですがあまり気にしていませんでした。一番の原因はopcacheを入れ忘れていたことが原因だと思います。

ベンチマーク結果が揺れていますが、同じハードウェアでも微妙なソフトウェアバージョンの違いで性能が結構変わります。しかし、より速いことには変わりはありません。

フレームワークの基本性能でPhalconのライバルとなるものはスクリプト系言語ではなく、コンパイラ系言語のWebアプリケーションフレームワークになります。.NET CLI、Java VMは速いです。例えば、Scala言語(Java VM)のPlay2は同じマシン、同様のベンチマークで2万3千リクエスト/秒程度です。

実際にアプリケーションを作るとセッッション管理やデータベースアクセスなどのオーバーヘッドのため簡単に桁違いに遅くなります。反対にいうとこの部分を速くできればスクリプト系とは桁違いに速いWebサービスを作れることを意味します。通常のスクリプト系言語では.NET CLIやJava VMにどうしても歯が立ちませんが、Phalconなら勝負になります。PHP7になるとスクリプト部分も高速になるので、かなり良い勝負になるのではないでしょうか?どうしようもない部分はZephirでネイティブ化も比較的簡単です。

投稿者: yohgaki