php缓冲器:eaccelerator与xcache性能测试对比
随着PHP流行,PHP的执行效率也越来越被大家关注,可以选择的缓存器也是越来越多,从老的php-memcache到eaccelerator还有新兴的xcache。为了挑选一个合适的缓存器决定自己实测一下,看看哪个缓存器的效率更高,由于php-memcache很少有人用了现在只测试eaccele
随着PHP流行,PHP的执行效率也越来越被大家关注,可以选择的缓存器也是越来越多,从老的php-memcache到eaccelerator还有新兴的xcache。为了挑选一个合适的缓存器决定自己实测一下,看看哪个缓存器的效率更高,由于php-memcache很少有人用了现在只测试eaccelerator和xcache。 硬件配置: CPU:Intel 2140(双核心) 内存:2G DDR667 硬盘:80G(IDE接口,2M缓存)
软件版本 系统:Mandriva 2008 free,apache-2.2.6,php-5.2.4,ZendOptimizer-3.3.0,mysql-5.0.45。 测试对象的版本:eaccelerator-0.9.5.2,xcache-1.2.1
eaccelerator与xcache都是手动编译安装,安装安装官方公布的安装步骤和参数,需要了解的可以登录他们的网站去看。考虑到对商业代码的支持,缓存器都安装为zend的扩展,同时两个缓存器的缓存大小都是64M(呵呵有点大一般16M就不小了)。测试的时候关于eaccelerator会测试两项,一项是默认的,一项是把eaccelerator的缓存目录放到tmpfs中,我叫他为eaccelerator的内存模式。关于tmpfs的情况可以看下这里http://lcuc.org.cn/node/304。
测试工具为ab,测试读取对象是phpMyAdmin-2.11.2,Discuz!_6.0.0_SC_GBK
phpMyAdmin部分
测试语句为:ab -n 100000 http://localhost/phpmyadmin
不安装任何缓存器
[root@mandriva phpmyadmin]# ab -n 100000 http://localhost/phpmyadmin This is ApacheBench, Version 2.0.40-dev apache-2.0 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Finished 100000 requests
Server Software: Apache/2.2.6 Server Hostname: localhost Server Port: 80
Document Path: /phpmyadmin Document Length: 337 bytes
Concurrency Level: 1 Time taken for tests: 20.699322 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Non-2xx responses: 100000 Total transferred: 59100000 bytes HTML transferred: 33700000 bytes Requests per second: 4831.08 [#/sec] (mean) Time per request: 0.207 [ms] (mean) Time per request: 0.207 [ms] (mean, across all concurrent requests) Transfer rate: 2788.21 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.0 0 0 Processing: 0 0 1.2 0 294 Waiting: 0 0 1.2 0 294 Total: 0 0 1.2 0 294
Percentage of the requests served within a certain time (ms) 50% 0 66% 0 75% 0 80% 0 90% 0 95% 0 98% 0 99% 0 100% 294 (longest request) 主要的性能指标是Requests per second,为了看着方便,只在第一次的给出所有反馈,其他的都之提供Requests per second
结果:Requests per second: 4831.08 [#/sec] (mean)
eAccelerator 结果:Requests per second: 4850.92 [#/sec] (mean)
eAccelerator 内存模式 结果:Requests per second: 4690.77 [#/sec] (mean)
xcache 结果:Requests per second: 4781.96 [#/sec] (mean)
发现eAccelerator与xcache可以同时安装,就也试验了一下。 eAccelerator+xcache 结果:Requests per second: 4791.29 [#/sec] (mean)
测试的结果是eAccelerator 内存模式胜出。不过这样似乎看不出缓存器的必要,同时phpMyAdmin也太单一了。下面开始对Discuz!_6.0.0_SC_GBK的请求测试,这样对国内的用户才更加有参考意义。
Discuz!部分 说明:Discuz!默认安装,不带任何的数据,Discuz!自带了缓存功能不过默认没有开启,不影响测试的结果。
测试语句为:ab -n 100000 http://localhost/bbs/index.php 针对Discuz!测试又增加了一句:ab -n 100000 -c 200 http://localhost/bbs/index.php 超BT^_^
ab -n 100000
不安装任何缓存器
[root@mandriva bbs]# ab -n 100000 http://localhost/bbs/index.php This is ApacheBench, Version 2.0.40-dev apache-2.0 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Finished 100000 requests
Server Software: Apache/2.2.6 Server Hostname: localhost Server Port: 80
Document Path: /bbs/index.php Document Length: 9251 bytes
Concurrency Level: 1 Time taken for tests: 2278.10424 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Total transferred: 958900000 bytes HTML transferred: 925100000 bytes Requests per second: 43.90 [#/sec] (mean) Time per request: 22.780 [ms] (mean) Time per request: 22.780 [ms] (mean, across all concurrent requests) Transfer rate: 411.07 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.0 0 0 Processing: 21 22 0.9 22 137 Waiting: 14 21 0.6 21 40 Total: 21 22 0.9 22 137
Percentage of the requests served within a certain time (ms) 50% 22 66% 22 75% 22 80% 23 90% 23 95% 23 98% 24 99% 24 100% 137 (longest request)
结果:Requests per second: 43.90 [#/sec] (mean)
eAccelerator 结果:Requests per second: 167.28 [#/sec] (mean)
eAccelerator 内存模式 结果:Requests per second: 168.53 [#/sec] (mean)
xcache 结果:Requests per second: 191.68 [#/sec] (mean)
ab -n 100000 -c 200
不安装任何缓存器 结果:Requests per second: 77.73 [#/sec] (mean)
eAccelerator 结果:Requests per second: 317.69 [#/sec] (mean)
eAccelerator 内存模式 结果:Requests per second: 325.86 [#/sec] (mean)
xcache 结果:Requests per second: 388.76 [#/sec] (mean)
这时候结果已经很明显了xcache胜出,各项的差距也拉大了。
结果:xcache的性能相当的不错,可以取代eAccelerator。eAccelerator的内存模式对eAccelerator的性能提升不是很大,用了反而会增加系统配置的复杂度。
同时要注意的是mysql的性能,在进行Discuz!部分测试的时候CPU占用率几乎是100%。在没有安装任何缓存器的时mysql的占用率只有10%左右,其他的都被apache占去。安装任何一款缓冲器时,单线程mysql的占用率35%左右,多线程的时候是40%左右,其他的都被apache占去。这样看来缓存器在php应用中是非常重要的,一个缓存器可以大大减轻apache的负担,所以建议所有的php用户都安装一个缓存器。
后记:这次的测试用的参数有点BT了^_^,不过我们就是想得到一个近似合理的测试结果,时间长一点也不过分。
上一篇: mysql时间函数总结_MySQL