WordPress 缓存插件性能对比
虽然原生态的 WordPress 效率实在底下,但是 WordPress 提供了很多插件,国外服务器领域里也有很多开源的缓存软件,这几天http://www.etsec.com.cn的服务器用上了 Varnish 缓存加速,现在每天轻松应付流量,系统的负载也不再升高,呵呵。这里贴一篇国外高手的文章,一些主流的 WordPress 缓存插件,以及和用上 Varnish 的 WordPress 性能的对比。
1、作者使用的插件下载以及版本号:
DB Cache (version 0.6) DB Cache Reloaded(version 2.0.2) W3 Total Cache(version 0.8.5.1) WP Cache (version 2.1.2) WP Super Cache(version 0.9.9) WP Widget Cache(version 0.25.2) WP File Cache(version 1.2.5) WP Varnish (in beta) WP Varnish ESI Widget(in beta)
2、生产环境:
Debian 3.1/Squeeze VPS Linux Kernel 2.6.33 Single core of a Xen Virtualized Xeon X3220 (2.40ghz) 2gb RAM CoW file is written on a Raid-10 System using 4x1tb 7200RPM Drives Apache 2.2.14 mpm-prefork PHP 5.3.1 WordPress 官方主题测试数据 Tests are performed from a Quadcore Xeon machine connected via 1000 Base T on the same switch and /24 as the VPS machine
3、测试使用的Bash代码:
FETCHES=1000 PARALLEL=10
/usr/sbin/apache2ctl stop /etc/init.d/mysql restart apache2ctl start echo Sleeping sleep 30 time (\ echo First Run;\ ab -n $FETCHES -c$PARALLEL http://example.com/;\ echo Second Run;\ ab -n $FETCHES -c$PARALLEL http://example.com/;\ \ echo First Run;\ ./http_load -parallel $PARALLEL -fetches$FETCHES wordpresstest;\ echo Second Run;\ ./http_load -parallel $PARALLEL -fetches$FETCHES wordpresstest;\ )
4、测试以下 URL 的 http_load:
http://www.etsec.com.cn/2010/03/hello-world/
http://www.etsec.com.cn/2008/09/layout-test/
http://www.etsec.com.cn/2008/04/simple-gallery-test/
http://www.etsec.com.cn/2007/12/category-name-clash/
http://www.etsec.com.cn/2007/12/test-with-enclosures/
http://www.etsec.com.cn/2007/11/block-quotes/
http://www.etsec.com.cn/2007/11/many-categories/
http://www.etsec.com.cn/2007/11/many-tags/
http://www.etsec.com.cn/2007/11/tags-a-and-c/
http://www.etsec.com.cn/2007/11/tags-b-and-c/
http://www.etsec.com.cn/2007/11/tags-a-and-b/
http://www.etsec.com.cn/2007/11/tag-c/
http://www.etsec.com.cn/2007/11/tag-b/
http://www.etsec.com.cn/2007/11/tag-a/
http://www.etsec.com.cn/2007/09/tags-a-b-c/
http://www.etsec.com.cn/2007/09/raw-html-code/
http://www.etsec.com.cn/2007/09/simple-markup-test/
http://www.etsec.com.cn/2007/09/embedded-video/
http://www.etsec.com.cn/2007/09/contributor-post-approved/
http://www.etsec.com.cn/2007/09/one-comment/
http://www.etsec.com.cn/2007/09/no-comments/
http://www.etsec.com.cn/2007/09/many-trackbacks/
http://www.etsec.com.cn/2007/09/one-trackback/
http://www.etsec.com.cn/2007/09/comment-test/
http://www.etsec.com.cn/2007/09/a-post-with-multiple-pages/
http://www.etsec.com.cn/2007/09/lorem-ipsum/
5、最终性能对比:
Sorted in Ascending order in terms of higher overall performance
Addon | Apachebench | Cold Start Warm Start | http_load | Cold Start Warm Start | ||
Req/Second | Time/Request | 50% within x ms | Fetches/Second | Min First Response | Avg First Response | |
Baseline | 4.97 | 201.006 | 2004 | 15.1021 | 335.708 | 583.363 |
5.00 | 200.089 | 2000 | 15.1712 | 304.446 | 583.684 | |
DB Cache | 4.80 | 208.436 | 2087 | 15.1021 | 335.708 | 583.363 |
Cached all SQL queries | 4.81 | 207.776 | 2091 | 15.1712 | 304.446 | 583.684 |
DB Cache | 4.87 | 205.250 | 2035 | 14.1992 | 302.335 | 621.092 |
Out of Box config | 4.94 | 202.624 | 2026 | 14.432 | 114.983 | 618.434 |
WP File Cache | 4.95 | 201.890 | 2009 | 15.8869 | 158.597 | 549.176 |
4.99 | 200.211 | 2004 | 16.1758 | 99.728 | 544.107 | |
DB Cache Reloaded | 5.02 | 199.387 | 1983 | 15.0167 | 187.343 | 589.196 |
All SQL Queries Cached | 5.03 | 200.089 | 1985 | 14.9233 | 150.145 | 586.443 |
DB Cache Reloaded | 5.06 | 197.636 | 1968 | 14.9697 | 174.857 | 589.161 |
Out of Box config | 5.08 | 196.980 | 1968 | 15.181 | 257.533 | 587.737 |
Widgetcache | 6.667 | 149.903 | 1492 | 15.0264 | 245.332 | 602.039 |
6.72 | 148.734 | 1487 | 15.1887 | 299.65 | 598.017 | |
W3 Total Cache | 153.45 | 65.167 | 60 | 133.1898 | 8.916 | 85.7177 |
DB Cache off, Page Caching with Memcached | 169.46 | 59.011 | 57 | 188.4 | 9.107 | 50.142 |
W3 Total Cache | 173.49 | 57.639 | 52 | 108.898 | 7.668 | 86.4077 |
DB Cache off, Minify Cache with Memcached | 189.76 | 52.698 | 48 | 203.522 | 8.122 | 43.8795 |
W3 Total Cache | 171.34 | 58.364 | 50 | 203.718 | 8.097 | 44.1234 |
DB Cache using Memcached | 190.01 | 52.269 | 48 | 206.187 | 8.186 | 42.4438 |
W3 Total Cache | 175.29 | 57.048 | 48 | 87.423 | 7.515 | 107.973 |
Out of Box config | 191.15 | 52.314 | 47 | 204.387 | 8.288 | 43.217 |
W3 Total Cache | 175.29 | 57.047 | 51 | 204.557 | 8.199 | 42.9365 |
Database Cache using APC | 191.19 | 52.304 | 48 | 200.612 | 8.11 | 44.6691 |
W3 Total Cache | 114.02 | 87.703 | 49 | 114.393 | 8.206 | 82.0678 |
Database Cache Disabled | 191.76 | 52.150 | 49 | 203.781 | 8.095 | 42.558 |
W3 Total Cache | 175.80 | 56.884 | 51 | 107.842 | 7.281 | 87.2761 |
Database Cache Disabled, Minify Cache using APC | 192.01 | 52.082 | 50 | 205.66 | 8.244 | 43.1231 |
W3 Total Cache | 104.90 | 95.325 | 51 | 123.041 | 7.868 | 74.5887 |
Database Cache Disabled, Page Caching using APC | 197.55 | 50.620 | 46 | 210.445 | 7.907 | 41.4102 |
WP Super Cache | 336.88 | 2.968 | 16 | 15.1021 | 335.708 | 583.363 |
Out of Box config, Half On | 391.59 | 2.554 | 16 | 15.1712 | 304.446 | 583.684 |
WP Cache | 161.63 | 6.187 | 12 | 15.1021 | 335.708 | 583.363 |
482.29 | 20.735 | 11 | 15.1712 | 304.446 | 583.684 | |
WP Super Cache | 919.11 | 1.088 | 3 | 190.117 | 1.473 | 47.9367 |
Full on, Lockdown mode | 965.69 | 1.036 | 3 | 975.979 | 1.455 | 9.67185 |
WP Super Cache | 928.45 | 1.077 | 3 | 210.106 | 1.468 | 43.8167 |
Full on | 970.45 | 1.030 | 3 | 969.256 | 1.488 | 9.78753 |
W3 Total Cache | 1143.94 | 8.742 | 2 | 165.547 | 0.958 | 56.7702 |
Page Cache using Disk Enhanced | 1222.16 | 8.182 | 3 | 1290.43 | 0.961 | 7.15632 |
W3 Total Cache | 1153.50 | 8.669 | 3 | 165.725 | 0.916 | 56.5004 |
Page Caching – Disk Enhanced, Minify/Database using APC | 1211.22 | 8.256 | 2 | 1305.94 | 0.948 | 6.97114 |
Varnish ESI | 2304.18 | 0.434 | 4 | 349.351 | 0.221 | 28.1079 |
2243.33 | 0.44689 | 4 | 4312.78 | 0.152 | 2.09931 | |
WP Varnish | 1683.89 | 0.594 | 3 | 369.543 | 0.155 | 26.8906 |
3028.41 | 0.330 | 3 | 4318.48 | 0.148 | 2.15063 |
6、总结:
Varnish 用来做缓存,因为是内存级别的,读取速度相当之快,所有其他的缓存插件都是浮云,唯一能媲美的是启用了Page Caching – Disk (Enhanced), Minify Caching – Alternative PHP Cache (APC), Database Caching – Alternative PHP Cache (APC)的 W3 Total Cache 插件。
萝卜网目前使用的方案是 Nginx (82端口) + Varnish (反向监听81)+ Nginx (再反向监听80),当然也可以尝试 Apache (82)+ Varnish(81) + Nginx (80),具体怎么配置就不是本文的讨论范围了。
至于为什么不用 Apache (81) + Nginx (80),因为 Nginx 用来做反向代理+缓存加速的话,是在硬盘读取的,而Varnish直接读取内存,速度明显加快,唯一头疼的就是太损耗内存,服务器8G的内存瞬间跑满,看来得花钱加大内存了 T_T