博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
安装Xcache缓存加速php及ab压力测试结果
阅读量:6993 次
发布时间:2019-06-27

本文共 6717 字,大约阅读时间需要 22 分钟。

XCache 是一个又快又稳定的 PHP opcode 缓存器. 经过良好的测试并在大流量/高负载的生产机器上稳定运行. 经过(在 linux 上)测试并支持所有现行 PHP 分支的最新发布版本, 如 PHP_5_1 PHP_5_2 PHP_5_3 PHP_5_4. 并完美支持线程安全/Windows. 与同类 opcode 缓存器相比更胜一筹, 比如能够快速跟进 PHP 版本. 


我的php为5.6.6版本,所以需要安装xcache3.2.0     

官网下载:

tar zxvf xcache-3.2.0.tar.gzcd xcache-3.2.0 /usr/local/php/bin/phpize   ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config # make installInstalling shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/

安装完成后会在上面的路径下生成xcache.so 文件;

php.ini文件加入xcache代码段(原文件为/usr/local/src/xcache-3.2.0/xcache.ini)

# vi /usr/local/php/etc/php.ini [xcache-common]extension = xcache.so [xcache.admin]xcache.admin.enable_auth = On xcache.admin.user = "xcache"xcache.admin.pass = ""[xcache]xcache.shm_scheme ="mmap"xcache.size=60Mxcache.count =1xcache.slots =8Kxcache.ttl=0xcache.gc_interval =0xcache.var_size=4Mxcache.var_count =1xcache.var_slots =8Kxcache.var_ttl=0xcache.var_maxttl=0xcache.var_gc_interval =300xcache.test =Offxcache.readonly_protection = Onxcache.mmap_path ="/tmp/xcache"xcache.coredump_directory =""xcache.cacher =Onxcache.stat=Onxcache.optimizer =Off[xcache.coverager]xcache.coverager =Onxcache.coveragedump_directory =""

保存退出后,重启apache,php -v 查看是否有xcache信息;

# /usr/local/php/bin/php -vPHP 5.6.6 (cli) (built: Jun 29 2015 17:23:08)Copyright (c) 1997-2015 The PHP GroupZend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies    with XCache v3.2.0, Copyright (c) 2005-2014, by mOo    with XCache Cacher v3.2.0, Copyright (c) 2005-2014, by mOo

或phpinfo.php 浏览器中查看;

xcache状态查询:

创建一个缓存文件:touch /tmp/xcache

拷贝xcache3.2.0目录下htdocs目录到你自己的网站目录下,自定义目录名为xcache;

# cp -r htdocs/ /data/www/blog/xcache/

生成md5密码,复制密码拷贝到刚才php.ini文件xcache.admin.pass="" 引号中。

# echo -n '123456' |md5sum

e10adc3949ba59abbe56e057f20f883e  

在浏览器访问 www.star.com/xcache/,弹出认证框输入用户名和密码访问;

ab压力测试进行对比:未安装xcache与安装xcache

使用DELL R420真机(使用discuz论坛首页测试)

在另一台机器上,使用ab压力测试;未安装xcache,3000次并发为118; 3万次并发为74-94之间;

[root@localhost ~]# ab -n 3000 -c 100 www.yong.com/forum.phpThis is ApacheBench, Version 2.3 <$Revision: 655654 $>Server Software:        ApacheServer Hostname:        www.yong.comServer Port:            80Document Path:          /forum.phpDocument Length:        13222 bytesConcurrency Level:      100Time taken for tests:   25.247 secondsComplete requests:      3000Failed requests:        0Write errors:           0Total transferred:      42018000 bytesHTML transferred:       39666000 bytesRequests per second:    118.82 [#/sec] (mean)  #每秒处理的请求数Time per request:       841.579 [ms] (mean)Time per request:       8.416 [ms] (mean, across all concurrent requests)Transfer rate:          1625.25 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        1    4   9.0      2      85Processing:    66  827 441.1    967    2003Waiting:       55  812 437.8    953    1992Total:         68  831 442.2    970    2031Percentage of the requests served within a certain time (ms)  50%    970  66%   1085  75%   1147  80%   1187  90%   1295  95%   1411  98%   1680  99%   1791 100%   2031 (longest request)

可以查看日志记录也是3000条

[root@localhost logs]# cat yong.com-access_log_20150820.log|wc -l3000

请求为3万次,测试结果如下:

[root@localhost ~]# ab -n 30000 -c 100 www.yong.com/forum.php Server Software:        ApacheServer Hostname:        www.yong.comServer Port:            80Document Path:          /forum.phpDocument Length:        13222 bytesConcurrency Level:      100Time taken for tests:   402.065 secondsComplete requests:      30000Failed requests:        2   (Connect: 0, Receive: 0, Length: 2, Exceptions: 0)Write errors:           0Total transferred:      420614188 bytesHTML transferred:       397069884 bytesRequests per second:    74.61 [#/sec] (mean)Time per request:       1340.216 [ms] (mean)Time per request:       13.402 [ms] (mean, across all concurrent requests)Transfer rate:          1021.62 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        1  170 639.2      4    7553Processing:    60 1161 1108.3   1037    9234Waiting:       54  911 534.1    975    7633Total:         63 1331 1406.5   1068   12650Percentage of the requests served within a certain time (ms)  50%   1068  66%   1208  75%   1323  80%   1482  90%   2672  95%   4181  98%   6083  99%   7630 100%  12650 (longest request)

系统负载,最高达到88

spacer.gif

开启xcache缓存后,3000次请求并发为368;3万次请求并发为103;系统负载最高只有2-4;

[root@localhost ~]# ab -n 3000 -c 100 http://www.yong.com/forum.phpServer Software:        Apache Server Hostname:        www.yong.comServer Port:            80Document Path:          /forum.phpDocument Length:        12579 bytesConcurrency Level:      100Time taken for tests:   8.132 secondsComplete requests:      3000Failed requests:        8   (Connect: 0, Receive: 0, Length: 8, Exceptions: 0)Total transferred:      39787499 bytesHTML transferred:       37732203 bytesRequests per second:    368.90 [#/sec] (mean)Time per request:       271.079 [ms] (mean)Time per request:       2.711 [ms] (mean, across all concurrent requests)Transfer rate:          4777.81 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        1   36  29.8     27     141Processing:    27  230 112.0    222     919Waiting:       17  196 104.1    178     864Total:         31  266 107.4    252     951Percentage of the requests served within a certain time (ms)  50%    252  66%    298  75%    333  80%    352  90%    398  95%    452  98%    518  99%    592 100%    951 (longest request)

请求为3万次,测试结果如下:

[root@localhost ~]# ab -n 30000 -c 100 http://www.yong.com/forum.phpServer Software:        Apache Server Hostname:        www.yong.comServer Port:            80Document Path:          /forum.phpDocument Length:        13233 bytesConcurrency Level:      100Time taken for tests:   290.761 secondsComplete requests:      30000Failed requests:        29963   (Connect: 0, Receive: 0, Length: 29963, Exceptions: 0)Total transferred:      397977862 bytesHTML transferred:       377424199 bytesRequests per second:    103.18 [#/sec] (mean)Time per request:       969.202 [ms] (mean)Time per request:       9.692 [ms] (mean, across all concurrent requests)Transfer rate:          1336.67 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        1  273 830.2      7    5700Processing:    18  693 1404.2    249    7851Waiting:       14  366 547.2    212    5480Total:         19  967 2080.8    276   12416Percentage of the requests served within a certain time (ms)  50%    276  66%    382  75%    480  80%    567  90%   2453  95%   6768  98%   9107  99%   9879 100%  12416 (longest request)

 每次ab压力测试的结果都不太准确,在虚拟机测试结果更不靠谱。特意找的真机测试,除了负载较高,内存使用竟然没太大变化;只能做参考用;

转载地址:http://dtivl.baihongyu.com/

你可能感兴趣的文章
登陆的键盘敲击事件
查看>>
执行计划基础 统计信息
查看>>
python MD5加密方法
查看>>
mysql连接jdbc查询代码
查看>>
SpringMVC10数据验证
查看>>
处理异常Error resolving template [/login], template might not exist or might not be accessible by......
查看>>
洛谷 P1147 连续自然数和 Label:等差数列
查看>>
线程间的同步和通信机制
查看>>
Python脚本实现值更新事件赋值过程记录日志监控
查看>>
[bzoj 1503][NOI 2004]郁闷的出纳员
查看>>
Java课程上机实验1_ConnectionManager
查看>>
node.js中通过dgram数据报模块创建UDP服务器和客户端
查看>>
FZU Tic-Tac-Toe -.- FZU邀请赛 FZU 2283
查看>>
外痔田螺用法
查看>>
异常:由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值...
查看>>
nginx访问静态文件配置
查看>>
mysql索引
查看>>
ubuntu server 14.04 上安装jdk1.8
查看>>
python file.tell() 在windows下需要注意的地方
查看>>
10种简单的数字滤波C语言源程序算法
查看>>