在LNAMP上的eAccelerator1.0与Xcache3.0性能对比测试

今天闲来无事,用自己的VPS作为测试平台,测试Xcache3.0和eAccelerator1.0哪个性能更好.第一次做这种事情,做得不够专业请指正,呵呵.

处理器:Intel(R) Xeon(R) CPU E31240 @ 3.30GHz × 2
内存:1GB
测试工具:使用Apache Benchmark作为压力测试工具,并发数10,请求数5000
软件:nginx1.2.6+apache2.2.23+mysql5.5.29+ZendEngine2.3.0+ZendGuardLoader3.3
测试网站:新建phpwind9.0论坛作为测试页面(为了避免被恶意攻击,测试结果隐藏了Hostname)

 

不使用eAccelerator1.0和Xcache3.0,测试结果:

Server Software: nginx/1.2.6
Server Hostname: ***.***.***
Server Port: 80

Document Path: /phpwind/
Document Length: 10903 bytes

Concurrency Level: 10
Time taken for tests: 283.546 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 57323498 bytes
HTML transferred: 54515000 bytes
Requests per second: 17.63 [#/sec] (mean)
Time per request: 567.091 [ms] (mean)
Time per request: 56.709 [ms] (mean, across all concurrent requests)
Transfer rate: 197.43 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 3
Processing: 308 567 31.1 564 699
Waiting: 300 517 29.1 515 642
Total: 308 567 31.1 564 699

Percentage of the requests served within a certain time (ms)
50% 564
66% 577
75% 585
80% 590
90% 607
95% 621
98% 638
99% 650
100% 699 (longest request)

 

只使用eAccelerator1.0,测试结果:

Server Software: nginx/1.2.6
Server Hostname: ***.***.***
Server Port: 80

Document Path: /phpwind/
Document Length: 10903 bytes

Concurrency Level: 10
Time taken for tests: 247.201 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 57323978 bytes
HTML transferred: 54515000 bytes
Requests per second: 20.23 [#/sec] (mean)
Time per request: 494.402 [ms] (mean)
Time per request: 49.440 [ms] (mean, across all concurrent requests)
Transfer rate: 226.46 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 4
Processing: 319 494 35.7 491 688
Waiting: 312 454 34.4 451 639
Total: 319 494 35.7 491 688

Percentage of the requests served within a certain time (ms)
50% 491
66% 505
75% 514
80% 520
90% 541
95% 559
98% 582
99% 598
100% 688 (longest request)

 

只使用Xcache3.0,测试结果:

Server Software: nginx/1.2.6
Server Hostname: ***.***.***
Server Port: 80

Document Path: /phpwind/
Document Length: 10903 bytes

Concurrency Level: 10
Time taken for tests: 1560.616 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 57323430 bytes
HTML transferred: 54515000 bytes
Requests per second: 3.20 [#/sec] (mean)
Time per request: 3121.232 [ms] (mean)
Time per request: 312.123 [ms] (mean, across all concurrent requests)
Transfer rate: 35.87 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 1
Processing: 1702 3120 183.2 3098 4918
Waiting: 1657 2976 175.0 2956 4745
Total: 1702 3120 183.2 3098 4920

Percentage of the requests served within a certain time (ms)
50% 3098
66% 3166
75% 3212
80% 3249
90% 3361
95% 3453
98% 3578
99% 3634
100% 4920 (longest request)

结果总结

结果令我很惊讶!!不知道是我的XCache3.0设置问题还是怎么回事,XCache3.0很慢啊,比不用还要慢!?!?而且在测试期间CPU平均负载达到了10!?!?但愿是我设置问题。。。自己先琢磨一阵,如果找到哪里出问题了,再来更新。。。。

就目前结果分析,eAccelerator1.0对LNAMP的加速效果明显。在并发数为10的情况下处理5000个请求,如果不用eAccelerator1.0,则要花费283.546秒,使用了以后,花费的时间减少到了247.201秒,足足减少了近40秒。

本次测试并发连接数为10,请求数为5000,就能有40秒差距,相信如果并发连接数更多,总的连接数更多,eAccelerator1.0的加速效果会更明显。所以对大流量高并发连接的网站来说,加速效果绝对是很给力的!

而对于XCache3.0。。。。我暂时不做评论。。。。也许是XCache3.0和ZendGuard3.3冲突了,这里先保留测试结果,等我琢磨透了再做评论。。。。

事实证明,XCache3.0和ZendGuard3.3并没有冲突,我把ZendGuard3.3禁用了,结果XCache3.0还是那样。。。

对于这次XCache3.0测试结果这么奇怪,为此我把我使用的XCache3.0的设置贴上来,欢迎指正:

[XCache]
extension = "/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/xcache.so"
xcache.admin.auth = On
xcache.admin.user = "xcache"
xcache.admin.pass = "8e6867a5d05144cf4761d6481fc674a8"
xcache.size = 64M
xcache.shm_scheme = "mmap"
xcache.count = 4
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
xcache.var_size = 16M
xcache.var_count = 4
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = On

给DirectAdmin装上IP黑名单杜绝密码穷举攻击

1.备份防火墙配置文件,并从DA官方下载新的防火墙配置文件:
cd /etc/init.d mv iptables iptables.backup wget http://files1.directadmin.com/services/all/iptables chmod 755 iptables

警告:DA官方提供的防火墙配置文件中打开的是SSH的默认端口22,如果你的SSH端口不是22,则会造成你无法远程登录!!!解决办法是下载DA的防火墙配置文件以后手动编辑它的端口白名单,使你自己定义的SSH端口为打开状态.

重启防火墙:
/etc/init.d/iptables restart

2.下载脚本block_ip.sh,该脚本可以列出IP黑名单,执行下述命令来安装这些脚本:
cd /usr/local/directadmin/scripts/custom wget http://files1.directadmin.com/services/all/block_ip.sh wget http://files1.directadmin.com/services/all/show_blocked_ips.sh wget http://files1.directadmin.com/services/all/unblock_ip.sh chmod 700 block_ip.sh show_blocked_ips.sh unblock_ip.sh

3.创建空的IP黑名单:
touch /root/blocked_ips.txt touch /root/exempt_ips.txt

4.最后一步不是必须的,但是为了避免自己被误拉黑,所以需要在进行上面设置后使用过一段时间而没有出现问题的时候再进行这一步。
自动将可疑IP加入黑名单,执行以下命令:
cd /usr/local/directadmin/scripts/custom wget http://files1.directadmin.com/services/all/brute_force_notice_ip.sh chmod 700 brute_force_notice_ip.sh

安装DirectAdmin后的常见问题

一.DirectAdmin磁盘和流量统计信息不正确,用户磁盘占用和流量统计始终为0

出现这种情况的原因通常是系统的计划任务有问题,DA官方给出的解决方案如下:
1.检查/usr/local/directadmin/data/task.queue文件是否存在,如果存在,且包含几条信息,那么就表示数据统计没有运行,因为这个文件正常情况下会定期删除。
2.检查/var/log/cron文件(如果是Debian的话,检查/var/log/syslog),看dataskq是否每分钟运行一次,如果不是,执行:
chmod 644 /etc/cron.d/directadmin_cron
/sbin/service crond restart

3.确保crond服务运行正常:
ps ax | grep cron
4.重启cron服务:
service crond restart
如果你的系统未安装crond,则先执行下述命令安装crond:
yum -y install vixie-cron cronie
启动crond:
service crond start
设置开机启动:
chkconfig crond on
5.如果上述一切都检查完毕,但是task.queue依旧不正常的话,执行下述命令手动运行dataskq:
/usr/local/directadmin/dataskq d

给PHP安装配置XCache3加速器

1.下载Xcache
wget http://xcache.lighttpd.net/pub/Releases/3.0.0/xcache-3.0.0.tar.gz
2.解压:
tar zxvf xcache-3.0.0.tar.gz
3.更改目录:
cd xcache-3.0.0
4.编译so:
/usr/local/php5/bin/phpize
5.安装:
./configure -with-php-config=/usr/local/php5/bin/php-config -enable-xcache --enable-xcache-optimizer make make install
6.修改php.ini文件:
vi /usr/local/etc/php5/cgi/php.ini
在文件末尾添加(记得把汉字替换为实际内容):
extension = "第5步编译后的xcache.so文件路径" xcache.admin.auth = On xcache.admin.user = "此处填写你设置的用户名" xcache.admin.pass = "此处填写你设置的密码的MD5值" xcache.size = 32M xcache.shm_scheme = "mmap" xcache.count = 4 xcache.slots = 8K xcache.ttl = 0 xcache.gc_interval = 0 xcache.var_size = 16M xcache.var_count = 1 xcache.var_slots = 8K xcache.var_ttl = 0 xcache.var_maxttl = 0 xcache.var_gc_interval = 300 xcache.test = Off xcache.readonly_protection = Off xcache.mmap_path = "/dev/zero" xcache.coredump_directory = "" xcache.cacher = On xcache.stat = On xcache.optimizer = Off

7.复制htdocs到网站根目录下xcache文件夹:
mkdir /var/www/html/xcache cp -R htdocs/* /var/www/html/xcache cd /var/www/html/xcache cp config.example.php config.php chown -R webapps:webapps *
在config.php文件末尾添加(把下面的汉字替换为实际内容):
$_SERVER["PHP_AUTH_USER"] = "此处填写你想要的用户名"; $_SERVER["PHP_AUTH_PW"] = "此处填写你想要的密码原文";

打开浏览器访问http://IP/xcache,输入上面设置的帐号和密码进入Xcache的测试页面

PHP5.3下加速器ZendGuardLoader安装

由于Zend新产品ZendGuardLoader的面世,Zend Optimizer已经不支持php5.3了,官方给出的版本是ZendGuardLoader代替,ZendGuardLoader的安装还是和原版差不多的:

官方下载地址,需要登录 http://www.zend.com/products/guard/downloads

下面的版本是已经找出来的下载地址,能直接下载。

Windows 版本Zend Guard Loader下载
http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-Windows.zip

Linux 32位Zend Guard Loader 下载:
wget -c http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz

Linux 64位Zend Guard Loader 下载:
wget -c http://downloads.zend.com/guard/5.5.0/ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz

解压源码包(注意如果是32位系统,记得把下面的x86_64替换成i386):

tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz mv ZendGuardLoader-php-5.3-linux-glibc23-x86_64 ZendGuardLoader cd ZendGuardLoader/ mkdir -p /usr/local/zend/ cp php-5.3.x/ZendGuardLoader.so /usr/local/zend/

在php.ini文件最后面加上:

[Zend Guard Loader] zend_extension="/usr/local/zend/ZendGuardLoader.so" zend_loader.enable=1 zend_loader.disable_licensing=0 zend_loader.obfuscation_level_support=3 zend_loader.license_path=

#结束后重启apache

在phpinfo 里能看到

This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies

出现 Zend Guard Loader v3.3 则说明安装成功。