24

WordPress サーバーで PHP 7 と古いバージョンを比較するこのベンチマークを再現しようとしました: http://talks.php.net/oz15#/wpbench

私の構成はほぼ同じで、サーバーには i7、SSD、16GB RAM、debian があります。サーバーソフトウェアはnginxです。驚いたことに、私の結果は上記のリンクとは大きく異なります。

私のテストでは、Siege ( https://www.joedog.org/siege-home/ ) は以下を出力します:

PHP 7.0.0RC1 の場合:

siege -c100 -r100 http://10.22.255.133/wordpress/
** SIEGE 3.0.8
** Preparing 100 concurrent users for battle.
The server is now under siege..      done.

Transactions:                  10000 hits
Availability:                  100.00 %
Elapsed time:                  131.61 secs
Data transferred:              95.77 MB
Response time:                 0.75 secs
Transaction rate:              75.98 trans/sec
Throughput:                    0.73 MB/sec
Concurrency:                   56.98
Successful transactions:       10000
Failed transactions:           0
Longest transaction:           1.01
Shortest transaction:          0.04

PHP 5.6.12 の場合:

siege -c100 -r100 http://10.22.255.133/wordpress/
** SIEGE 3.0.8
** Preparing 100 concurrent users for battle.
The server is now under siege..      done.

Transactions:                  10000 hits
Availability:                  100.00 %
Elapsed time:                  63.41 secs
Data transferred:              95.77 MB
Response time:                 0.03 secs
Transaction rate:              157.70 trans/sec
Throughput:                    1.51 MB/sec
Concurrency:                   4.45
Successful transactions:       10000
Failed transactions:           0
Longest transaction:           0.63
Shortest transaction:          0.01

トランザクション レートを見ると、PHP 5 は PHP 7 の約 2 倍高速であることがわかります。信じられません。

もう 1 つの興味深い事実は、このベンチマーク ( http://www.php-benchmark-script.com/ ) を実行すると、PHP 7 が PHP 5 よりも約 3 倍高速になることです (もちろん、私がテストした同じサーバー上で)ワードプレス)。測定結果は次のとおりです。

  • PHP 7.0.0RC1 | PHP 5.5.28
  • 数学: 0.201 | 0.683
  • 文字列操作: 0.271 | 0.77
  • ループ: 0.166 | 0.486
  • それ以外の場合: 0.12 | 0.295

役立つ場合に備えて、両方の phpinfo() ファイルをアップロードしました。

私のWordpressでのテストで、なぜPHP 7がそれほど遅くなったのか分かりますか?


opcacheを有効にすると、 PHP 7 は実際には PHP 5 の 2 倍の速度になります。ヒントをくれた Mjh に感謝します!

ランダムに満たされた WordPress サーバーで次の測定を行いました。

Siege は、 PHP 7.0.0RC1に対して以下を出力するようになりました。

Transactions:                  10000 hits
Availability:                 100.00 %
Elapsed time:                  62.14 secs
Data transferred:             604.20 MB
Response time:                  0.02 secs
Transaction rate:             160.93 trans/sec
Throughput:                     9.72 MB/sec
Concurrency:                    3.77
Successful transactions:       10000
Failed transactions:               0
Longest transaction:            0.41
Shortest transaction:           0.01 

そしてPHP 5.6.12

siege -c100 -r100 http://10.22.255.133/wordpress/
** SIEGE 3.0.8
** Preparing 100 concurrent users for battle.
The server is now under siege..      done.

Transactions:                 10000 hits
Availability:                 100.00 %
Elapsed time:                 119.98 secs
Data transferred:             604.20 MB
Response time:                0.60 secs
Transaction rate:             83.35 trans/sec
Throughput:                   5.04 MB/sec
Concurrency:                  49.86
Successful transactions:      10000
Failed transactions:          0
Longest transaction:          4.06
Shortest transaction:         0.04
4

2 に答える 2

21

phpinfo投稿した出力によると、opcachePHP 7 では有効になっていませんが、PHP 5 では有効です。それだけで大きな違いが生じる可能性があります。

于 2015-09-24T18:52:30.987 に答える
-2

現在、CLI 側でも同じ驚くべき結果が得られています。

私の古いプロジェクトの 1 つは PHING ビルドを使用しています。PHP 5.3、次にPHP 5.6で実行されていました。PHP 7 を使用してみましたが、大きな違いがあることに気付きました。そこで、スクリプトの実行時間を計ることにしました。

参考までに、ビルド中に何千ものファイルが処理される実際のプロジェクトです。

PHP 5.3.29 を使用してビルド: 3 分 44 秒が経過しました。

PHP 7.2.11 を使用してビルド: 11 分 41 秒が経過しました。

CLI で opcache が有効になっていないことに気付きました。opcache の結果は次のとおりです。

PHP 7.2.11 + opcache を使用してビルド: 12 分 18 秒経過。

はい、悪い

ご参考までに:

$ php --info |grep opcache
opcache.blacklist_filename => no value => no value
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => On => On
opcache.enable_cli => On => On
opcache.enable_file_override => Off => Off
opcache.error_log => no value => no value
opcache.file_cache => no value => no value
opcache.file_cache_consistency_checks => 1 => 1
opcache.file_cache_only => 0 => 0
opcache.file_update_protection => 2 => 2
opcache.force_restart_timeout => 180 => 180
opcache.huge_code_pages => Off => Off
opcache.inherited_hack => On => On
opcache.interned_strings_buffer => 8 => 8
opcache.lockfile_path => /tmp => /tmp
opcache.log_verbosity_level => 1 => 1
opcache.max_accelerated_files => 10000 => 10000
opcache.max_file_size => 0 => 0
opcache.max_wasted_percentage => 5 => 5
opcache.memory_consumption => 128 => 128
opcache.opt_debug_level => 0 => 0
opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF
opcache.preferred_memory_model => no value => no value
opcache.protect_memory => 0 => 0
opcache.restrict_api => no value => no value
opcache.revalidate_freq => 2 => 2
opcache.revalidate_path => Off => Off
opcache.save_comments => 1 => 1
opcache.use_cwd => On => On
opcache.validate_permission => Off => Off
opcache.validate_root => Off => Off
opcache.validate_timestamps => On => On

ところで、PHP 5 から PHP 7 に切り替えたときに、apache を使用した製品で大きな違いに気付いたことは一度もないと言わざるを得ません。オンラインで見られるすべてのベンチマークにもかかわらず、違いは明らかではありません。

言うまでもなく、そのプロジェクトでは、PHP 5 バージョンに固執します。

于 2018-11-01T10:44:07.553 に答える