eAccelerator,插件对wordpress调入速度的影响和分析

软硬天师   评论

用wordpress开站有一段时间了,随着插件和定制化模板的应用,发现博客首页打开的速度越来越慢。去年在为一个魔兽工会建论坛的时候,有接触过同样构建在LAMP上的论坛程序vbulletin,当时考虑到论坛的并发访问特性,安装了PHP加速扩展ea(eAccelerator 0.5.9), 效果非常好,基本上能达到提速一倍的效果(详情待会儿看下面详细分析)。

因为我的博客和论坛是装在一台主机上的,想来ea对博客也应该同时有效。跑了两边ab(apache bench,apache自带的性能评测小工具),分别打开ea和不打开ea。打开ea时,博客反应速度确实是不打开ea的一倍,但是当我把去年ea跑vbulletin数据从箱底翻出来对照后,发现vb主页比wp主页要快3-4倍。当然这样的比较本身没多大的意义,ab测的也是并发多重连接时服务器的反应,wp本身并发连接量应该不大。但还是比较了一下是因为究其原理,vb和wp似乎是很像的。首先,vb和wp都是严重依赖数据库存储数据的php应用,vb首页有论坛列表,点入某子论坛,有主题列表,这个wp首页有帖子列表颇为相像,其次点入某主题后,vb主题有楼主和回帖内容,而wp也有主题细节和评论回复。如果把图文和外链做比较的话,wp比vb就要多的多了。这是不是主要原因呢?

下面来看看ab数据(下面的ab命令中,-n是总计连接数量,-c是并发连接数量,这里我们取总计1000次连接,10个并发连接为一个请求)

先是wordpress打开ea的结果
wordpress(www.sbtalk.com.cn)[with eaccelerator]

—————————————————————
# ab -n1000 -c10 -dS -eea.csv http://www.sbtalk.com.cn/index.php
Benchmarking www.sbtalk.com.cn (be patient)
Finished 1000 requests

Document Path: /index.php
Document Length: 41733 bytes

Concurrency Level: 10
Time taken for tests: 285.383968 seconds
Complete requests: 1000
Total transferred: 42153898 bytes
HTML transferred: 41919810 bytes
Requests per second: 3.50 [#/sec] (mean)
Time per request: 2853.840 [ms] (mean)
Time per request: 285.384 [ms] (mean, across all concurrent requests)
Transfer rate: 144.24 [Kbytes/sec] received

接着是是wordpress不打开ea的结果
wordpress(www.sbtalk.com.cn)[without eaccelerator]

——————————————————————-
# ab -n1000 -c10 -dS -eea.csv http://www.sbtalk.com.cn/index.php
Benchmarking www.sbtalk.com.cn (be patient)
Finished 1000 requests

Document Path: /index.php
Document Length: 41733 bytes

Concurrency Level: 10
Time taken for tests: 530.667060 seconds
Complete requests: 1000
Total transferred: 42088209 bytes
HTML transferred: 41854817 bytes
Requests per second: 1.88 [#/sec] (mean)
Time per request: 5306.671 [ms] (mean)
Time per request: 530.667 [ms] (mean, across all concurrent requests)
Transfer rate: 77.45 [Kbytes/sec] received

对比结果,打开ea后,wordpress跑完1000次连接只要280秒,而不打开ea的情况下要530秒。如果以time per request的数量来看,ea后需要2.8秒打开一个完整首页,没有ea则需要5.3秒,差距居然有2.5秒之巨。

下面来看看我去年在同一台主机上(有兴趣的可以ping一下,其实是同一个IP),用ab测vbulletin的情况。该论坛目前状况是
(主题: 10,461, 帖子: 84,601, 会员: 473, 活跃的会员: 288),是个小型论坛。

vbulletin打开ea的结果
wow.funline.com.cn/forum [with eaccelerator]
————————————————————
# ab -n1000 -c10 -dS -eea.csv http://wow.funline.com.cn/index.php
Benchmarking wow.funline.com.cn (be patient)
Finished 1000 requests

Document Path: /index.php
Document Length: 63876 bytes

Concurrency Level: 10
Time taken for tests: 79.489914 seconds
Complete requests: 1000
Total transferred: 64388520 bytes
HTML transferred: 64003752 bytes
Requests per second: 12.58 [#/sec] (mean)
Time per request: 794.899 [ms] (mean)
Time per request: 79.490 [ms] (mean, across all concurrent requests)
Transfer rate: 791.03 [Kbytes/sec] received

最后是vbulletin不打开ea的结果
wow.funline.com.cn/forum [without eaccelerator]
————————————————————
# ab -n1000 -c10 -dS -eea.csv http://wow.funline.com.cn/index.php
Benchmarking wow.funline.com.cn (be patient)
Finished 1000 requests

Server Software: Apache/2.0.59
Server Hostname: wow.funline.com.cn
Server Port: 80

Document Path: /index.php
Document Length: 64203 bytes

Concurrency Level: 10
Time taken for tests: 148.842618 seconds
Complete requests: 1000
Total transferred: 64861623 bytes
HTML transferred: 64476855 bytes
Requests per second: 6.72 [#/sec] (mean)
Time per request: 1488.426 [ms] (mean)
Time per request: 148.843 [ms] (mean, across all concurrent requests)
Transfer rate: 425.56 [Kbytes/sec] received

可以看见,打开ea后,bulletin只要79秒就跑完1000次连接了,不打开ea,大概在148秒左右,基本上也是1倍的提速。vb在这里比wp要快的多,这可能跟首页的内容不同有关,论坛类型的首页只是子论坛文字列表,而博客的首页往往外链和图片居多,再加上一些rss的feed link。

ea的提速作用,主要是把已解释的php代码放在内存里,提高调用速度,因此,我单独跑了100次连接的ab,到后台去看了看php代码在ea中的命中状况,结果全部命中,另有一个额外的发现是,插件中不管首页是否有用到,只要是激活的,wordpress一样每次都会调用,因为可以看见命中次数也是100左右,比如图中的sitemap插件,而没有激活的hello dolly插件,在列表中就没有显示。

eaccelerator01.png

观察列表可以发现,像sitemap这类插件达450k之巨,而且每次都要调用到内存里解释执行,事实上这类插件是后台管理类的,完全可以每次写post后激活,再手工运行一次。为了测试性能的影响程度,我选了5个可有可无或者不影响前台的插件deactived(admin dropmenu,comment-subscribe,google sitemap,advanced-tinyMCE 和popularity contest)后,分别在with ea和without ea的情况下跑了ab(1000次连接),结果如下

wordpress deactived 5 plugin [with eaccelerator]
———————————————————-

# ab -n1000 -c10 -dS -eea.csv http://www.sbtalk.com.cn/index.php
Benchmarking www.sbtalk.com.cn (be patient)
Finished 1000 requests

Document Path: /index.php
Document Length: 41638 bytes

Concurrency Level: 10
Time taken for tests: 268.527384 seconds
Complete requests: 1000
Total transferred: 42008739 bytes
HTML transferred: 41775347 bytes
Requests per second: 3.72 [#/sec] (mean)
Time per request: 2685.274 [ms] (mean)
Time per request: 268.527 [ms] (mean, across all concurrent requests)
Transfer rate: 152.77 [Kbytes/sec] received

wordpress deactived 5 plugin [without eaccelerator]
————————————————————–

# ab -n1000 -c10 -dS -eea.csv http://www.sbtalk.com.cn/index.php
Benchmarking www.sbtalk.com.cn (be patient)
Finished 1000 requests

Document Path: /index.php
Document Length: 41638 bytes

Concurrency Level: 10
Time taken for tests: 494.602964 seconds
Complete requests: 1000
Total transferred: 41927856 bytes
HTML transferred: 41694696 bytes
Requests per second: 2.02 [#/sec] (mean)
Time per request: 4946.030 [ms] (mean)
Time per request: 494.603 [ms] (mean, across all concurrent requests)
Transfer rate: 82.78 [Kbytes/sec] received

结果显示,打开ea情况下1000次连接平均减少了17秒(=285-268),不打开ea的情况下减少了36秒(=530-494),减少的时间差不多也是一倍。

一般提供php引擎的博客服务托管商Zend Engine加速应该都会打开,但是据说效果并不好,eAccelerator对于php的加速还是有不错的口碑的,根据上述测试,10个人同时浏览作为一个请求,差别竟然有2.5秒之巨,但是如果不是自己的主机就很难进入配置了。我们能做的也就是少装点插件,按照上述测试的情况下能减少0.5秒的首页调入时间。下面把Time per request数据按照不同的配置列一下,便于大家比较:

正常状态打开ea : 2853.840 [毫秒] (平均)
正常状态关闭ea : 5306.671 [毫秒] (平均)
卸载5个插件同时打开ea : 2685.274 [毫秒] (平均)
卸载5个插件同时关闭ea : 4946.030 [毫秒] (平均)

这个数字是10个并发连接所需时长,也就是假设10个人通过主页,单页,rss reader等不同方式同时访问博客页面,所需的反馈时间,因为上面测的是1000次连接,所以这个数字x100就是1000次连接(按照10个并发同时连)的总时长。

综上分析,插件等对wordpress页面调入速度在没有ea的情况下,大概是一个插件0.1秒的速度影响(应该已经涵盖了数据库调用的时间),如果你装有10-30个插件的话,速度影响基本上会在1-3秒。而如果是自主主机能有配置权限的话,使用eAccelerator能够很有效的加速wordpress的调入速度,这在使用php为脚本语言的主机上也是得到普遍验证了的。

6条评论 to “eAccelerator,插件对wordpress调入速度的影响和分析”

  1. Gravatar 偶爱偶家

    看看ms不错

    [回复]

  2. Gravatar 帕兰卓一得

    还是更喜欢傻瓜式的教学!!!这样长篇大论高深莫测的。头痛!!!!

    [回复]

  3. Gravatar 央街浪子

    @帕兰卓一得:是啊,以后写一篇怎么在独立主机上加载ea的文章。

    [回复]

  4. Gravatar Vern

    快写吧,我正愁自己博客慢呢

    [回复]

  5. [...] 原文出处:http://www.sbtalk.com.cn/2007/06/23/eaccelerator_plugin_impact_for_wordpress.html Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages. [...]

  6. Gravatar Ryan

    写的不错。
    博主有没有测试过zend only,ea only, zend+ea一起的效果呢?

    [回复]

发布评论

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS 登录