HHVM vs PHP-FPM

@zen
2014年7月2日

〇 基准性能测试#

HHVM 会篡改 phpinfo() 函数输出结果,因此使用最基本的 echo 'Hello World!'; 进行测试。

0.1 测试环境#

在 OS X 10.9.3 使用 VirtualBox 4.3.12 r93733 创建虚拟机,配置如下:

# uname -a
Linux sandbox-1 3.2.0-4-amd64 #1 SMP Debian 3.2.57-3+deb7u2 x86_64 GNU/Linux

# dpkg -l
||/ Name                                   Version                  Architecture
+++-======================================-========================-============
ii  nginx-full                             1.4.6-1~dotdeb.1         amd64
ii  php5-fpm                               5.5.10-1~dotdeb.1        amd64
ii  hhvm                                   3.1.0~wheezy             amd64

# free -h
             total
Mem:          496M
Swap:         487M

# # grep 'processor\s*:' /proc/cpuinfo | wc -l
2

# ulimit -n
65535

# cat /etc/nginx/nginx.conf
worker_processes 2;
	worker_connections 1024;
	keepalive_timeout 15;
	
# cat /etc/php5/fpm/pool.d/www.conf
listen.backlog = 4096
pm = static
pm.max_children = 4

$ ab -V
This is ApacheBench, Version 2.3 <$Revision: 655654 $>

0.2 测试结果#

统一使用 ab -c 100 -n 10000 http://127.0.0.1/ 度量。

每次测试前,确认服务为新启动,且网络链接情况恢复正常。

PHP-FPM#

  1. TCP

    ` Time taken for tests: 5.366 seconds Failed requests: 0 Write errors: 0 Requests per second: 1863.51 [#/sec] (mean) Time per request: 53.662 [ms] (mean)

    Connection Times (ms)

               min  mean[+/-sd] median   max
    

    Connect: 0 3 4.5 1 24 Processing: 5 50 13.4 50 98 Waiting: 5 48 13.7 48 98 Total: 13 53 11.3 53 98

    Percentage of the requests served within a certain time (ms) 50% 53 75% 58 90% 66 98% 84 100% 98 (longest request) `

  2. Unix Socket

    ` Time taken for tests: 4.231 seconds Failed requests: 0 Write errors: 0 Requests per second: 2363.37 [#/sec] (mean) Time per request: 42.312 [ms] (mean)

    Connection Times (ms)

               min  mean[+/-sd] median   max
    

    Connect: 0 7 5.6 6 27 Processing: 4 35 10.5 34 83 Waiting: 4 32 10.9 31 83 Total: 14 42 8.0 41 83

    Percentage of the requests served within a certain time (ms) 50% 41 75% 47 90% 54 98% 60 100% 83 (longest request) `

HHVM#

为真实展现 HHVM 处理能力,按照其官方文档,在 Nginx 配置中启用了 fastcgi_keep_conn 指令。

  1. TCP

    ` Time taken for tests: 7.788 seconds Failed requests: 0 Write errors: 0 Requests per second: 1284.09 [#/sec] (mean) Time per request: 77.876 [ms] (mean)

    Connection Times (ms)

               min  mean[+/-sd] median   max
    

    Connect: 0 0 1.0 0 16 Processing: 14 77 5.7 76 109 Waiting: 14 77 5.7 76 109 Total: 29 78 5.6 77 113

    Percentage of the requests served within a certain time (ms) 50% 77 75% 80 90% 85 98% 90 100% 113 (longest request) `

  2. Unix Socket

    ` Time taken for tests: 7.615 seconds Failed requests: 0 Write errors: 0 Requests per second: 1313.28 [#/sec] (mean) Time per request: 76.145 [ms] (mean)

    Connection Times (ms)

               min  mean[+/-sd] median   max
    

    Connect: 0 1 1.1 1 13 Processing: 53 75 5.9 75 117 Waiting: 53 74 5.8 74 116 Total: 54 76 6.2 76 125

    Percentage of the requests served within a certain time (ms) 50% 76 75% 79 90% 82 98% 93 100% 125 (longest request) `

0.3 摘要对比#

PHP-FPMHHVM
TCPUnix SocketTCPUnix Socket
Requests per second [#/sec]1863.512363.371284.091313.28
Time per request [ms]53.66242.31277.87676.145
... 98% [ms]84609093