PHP ·

PHP7 VS HHVM (WordPress)

 

其实我已经在很多场合说过, PHP7的性能已经和HHVM相当了..

但是呢, 总是有人问…

另外感觉微博并不能特别好的留存, 所以我写个BLOG吧.

这篇BLOG, 我将进行最客观的对比测试, 就用ab来压测一下Wordpress的首页..

来对比看看PHP7和HHVM-3.2.0的性能在Wordpress上的性能对比.

机器配置:

CPU: 4 X Intel(R) Xeon(R) CPU           E5410  @ 2.33GHz
Mem: 16G

环境配置:

Nginx + PHP-FPM
Nginx + HHVM

软件版本:

PHP7 - 79354ba6d0d6a1a4596f9ac66ee9bc3a34ed972b
HHVM-3.2.0

HHVM的配置:

$ cat /etc/hhvm/server.ini
; php options

pid = /var/run/hhvm/pid

; hhvm specific

hhvm.server.host = 127.0.0.1
hhvm.server.port = 9000
hhvm.server.type = fastcgi
;hhvm.server.file_socket = /var/run/hhvm/hhvm.sock
hhvm.server.default_document = index.php
hhvm.log.level = Error
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.log.use_log_file = true
hhvm.log.file = /var/run/hhvm/error.log
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc
hhvm.mysql.typed_results = false

PHP的配置(pm.max_children和你的cpu核数相当):

php-fpm.conf:
pm = static
pm.max_children = 4

php.ini (opcache):
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1

opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.save_comments=0
opcache.fast_shutdown=1
opcache.enable_file_override=1

为了显示测试的客观性, 我决定采用屏幕录制的办法, 我会把我测试的时候的过程录制下来. 大家参看即可..

视频:

测试结果如下(俩个测试都会首先用100个请求预热, 然后开始100个并发, 10000个请求ab压测):

PHP7:

Concurrency Level:      100
Time taken for tests:   38.726 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      89290000 bytes
HTML transferred:       86900000 bytes
Requests per second:    258.22 [#/sec] (mean)
Time per request:       387.260 [ms] (mean)
Time per request:       3.873 [ms] (mean, across all concurrent requests)
Transfer rate:          2251.64 [Kbytes/sec] received

HHVM-3.2

Document Path:          /wordpress/
Document Length:        8690 bytes

Concurrency Level:      100
Time taken for tests:   43.296 seconds
Complete requests:      10000
Failed requests:        0
Write errors:           0
Total transferred:      89260000 bytes
HTML transferred:       86900000 bytes
Requests per second:    230.97 [#/sec] (mean)
Time per request:       432.957 [ms] (mean)
Time per request:       4.330 [ms] (mean, across all concurrent requests)
Transfer rate:          2013.31 [Kbytes/sec] received

结论,

PHP7 – 258.22 QPS

HHVM – 230.97 QPS

PHP7的在真实场景的性能确实已经和HHVM相当, 在一些场景甚至超过了HHVM(PS: 我是想基于HHVM-3.3测试, 但是我的Ubuntu 13.10实在是编译不成功, 所以拿3.2测试, 他们的差别也不会太大).

最后, PHP7将会在明年10月发布正式版, 我相信我们还会让它更快, 大家拭目以待吧

PS: 我之所以发这个文章, 还有一个原因, 是因为某公司发表了一系列的文章来谈他们迁移HHVM. 其中有一这么一段, 是他们发现业务在PHP5.5(注意还不是7哦)和HHVM之间并没有他们期望的大的性能区别, 于是他们针对HHVM和PHP5.5分别做了优化以后, 再来对比, 得出一个”通用结论”.

那么问题就来了, 这就相当于是用HHVM写了个功能,然后用PHP又写了一个功能, 这俩者代码不完全相同, 逻辑不完全相同, 你能用这个对比来做出一个”通用结论”么?

因为, 你针对PHP的优化, 到底做了多少, 做的好不好, 很难评价, 也许换个人做优化, 还能得出完全相反的结论(就比如, 我们基于PHP5.4, 也做了一些优化, 让微博手机服务端的性能提升了2.6倍, 服务器减少了60%, 这又怎么说: 优化介绍: 微博LAMP性能优化之路)?

那个文章还有这么一句:”hhvm是基于php5.4的语法标准,因此,hhvm和php5.5与我们目前用的php5.2都存在语法差异,php5.5差异更大一些。”

这个叫做差异? 5.5对5.2那可是99%的兼容… 你把HHVM的不兼容点和PHP5.5的新语法都叫做差异? 那是一回事么?

参与评论