安装Xcache缓存加速php及ab压力测试结果

简介:

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     

官网下载:http://xcache.lighttpd.net/

1
2
3
4
5
6
tar  zxvf xcache-3.2.0. tar .gz
cd  xcache-3.2.0
  /usr/local/php/bin/phpize  
  . /configure  -- enable -xcache --with-php-config= /usr/local/php/bin/php-config 
# make install
Installing 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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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=60M
xcache.count =1
xcache.slots =8K
xcache.ttl=0
xcache.gc_interval =0
xcache.var_size=4M
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 = On
xcache.mmap_path = "/tmp/xcache"
xcache.coredump_directory = ""
xcache.cacher =On
xcache.stat=On
xcache.optimizer =Off
[xcache.coverager]
xcache.coverager =On
xcache.coveragedump_directory = ""

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

1
2
3
4
5
6
# /usr/local/php/bin/php -v
PHP 5.6.6 (cli) (built: Jun 29 2015 17:23:08)
Copyright (c) 1997-2015 The PHP Group
Zend 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 浏览器中查看;

wKioL1XWklTRu3JsAAJzJjqvLfY186.jpg


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/,弹出认证框输入用户名和密码访问;

wKioL1XWkszhmHHdAAD8G30QvrM268.jpg


wKiom1XWkMqRZDXmAAPPHydcvdE335.jpg


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

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[root@localhost ~] # ab -n 3000 -c 100 www.yong.com/forum.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Server Software:        Apache
Server Hostname:        www.yong.com
Server Port:            80
Document Path:           /forum .php
Document Length:        13222 bytes
 
Concurrency Level:      100
Time taken  for  tests:   25.247 seconds
Complete requests:      3000
Failed requests:        0
Write errors:           0
Total transferred:      42018000 bytes
HTML transferred:       39666000 bytes
Requests 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 ] received
Connection Times (ms)
               min  mean[+ /-sd ] median   max
Connect:        1    4   9.0      2      85
Processing:    66  827 441.1    967    2003
Waiting:       55  812 437.8    953    1992
Total:         68  831 442.2    970    2031
Percentage 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条

1
2
[root@localhost logs] # cat yong.com-access_log_20150820.log|wc -l
3000

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[root@localhost ~] # ab -n 30000 -c 100 www.yong.com/forum.php 
Server Software:        Apache
Server Hostname:        www.yong.com
Server Port:            80
Document Path:           /forum .php
Document Length:        13222 bytes
 
Concurrency Level:      100
Time taken  for  tests:   402.065 seconds
Complete requests:      30000
Failed requests:        2
    (Connect: 0, Receive: 0, Length: 2, Exceptions: 0)
Write errors:           0
Total transferred:      420614188 bytes
HTML transferred:       397069884 bytes
Requests 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 ] received
Connection Times (ms)
               min  mean[+ /-sd ] median   max
Connect:        1  170 639.2      4    7553
Processing:    60 1161 1108.3   1037    9234
Waiting:       54  911 534.1    975    7633
Total:         63 1331 1406.5   1068   12650
Percentage 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.gifwKioL1XWkzSRiBoUAAGzHdjvgs4451.jpg

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[root@localhost ~] # ab -n 3000 -c 100 http://www.yong.com/forum.php
Server Software:        Apache 
Server Hostname:        www.yong.com
Server Port:            80
Document Path:           /forum .php
Document Length:        12579 bytes
 
Concurrency Level:      100
Time taken  for  tests:   8.132 seconds
Complete requests:      3000
Failed requests:        8
    (Connect: 0, Receive: 0, Length: 8, Exceptions: 0)
Total transferred:      39787499 bytes
HTML transferred:       37732203 bytes
Requests 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 ] received
Connection Times (ms)
               min  mean[+ /-sd ] median   max
Connect:        1   36  29.8     27     141
Processing:    27  230 112.0    222     919
Waiting:       17  196 104.1    178     864
Total:         31  266 107.4    252     951
Percentage 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万次,测试结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[root@localhost ~] # ab -n 30000 -c 100 http://www.yong.com/forum.php
Server Software:        Apache 
Server Hostname:        www.yong.com
Server Port:            80
Document Path:           /forum .php
Document Length:        13233 bytes
 
Concurrency Level:      100
Time taken  for  tests:   290.761 seconds
Complete requests:      30000
Failed requests:        29963
    (Connect: 0, Receive: 0, Length: 29963, Exceptions: 0)
Total transferred:      397977862 bytes
HTML transferred:       377424199 bytes
Requests 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 ] received
Connection Times (ms)
               min  mean[+ /-sd ] median   max
Connect:        1  273 830.2      7    5700
Processing:    18  693 1404.2    249    7851
Waiting:       14  366 547.2    212    5480
Total:         19  967 2080.8    276   12416
Percentage 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压力测试的结果都不太准确,在虚拟机测试结果更不靠谱。特意找的真机测试,除了负载较高,内存使用竟然没太大变化;只能做参考用;






本文转自 模范生 51CTO博客,原文链接:http://blog.51cto.com/mofansheng/1686766,如需转载请自行联系原作者
目录
相关文章
|
1月前
|
运维 JavaScript 应用服务中间件
os-copilot安装与多项功能测评,帮助开发人员PHP环境排查问题
本文介绍了OS Copilot在ECS上 Alibaba Cloud Linux的安装与使用,并对其多项参数进行了功能测评。OS Copilot是为操作系统提供智能化辅助的工具,支持自动化任务、智能推荐、故障排查等功能。安装时需检查是否已安装(`rpm -q os-copilot`),若未安装则用`yum install os-copilot`命令安装,并配置AccessKey信息连接阿里云服务。通过测试不同参数命令,如`-t`参数,展示了其自动化执行和智能生成回答的能力,显著提升运维效率。
os-copilot安装与多项功能测评,帮助开发人员PHP环境排查问题
|
15天前
|
监控 Linux PHP
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
65 20
|
3月前
|
Java 程序员 PHP
01 入门PHP就来我这-安装phpstudy
路老师的PHP入门教程,带你从零开始学习PHP。首先下载并安装phpStudy,接着配置域名和端口,最后创建并运行第一个PHP文件。内容详实,适合初学者。
84 3
01 入门PHP就来我这-安装phpstudy
|
3月前
|
缓存 NoSQL PHP
Redis作为PHP缓存解决方案的优势、实现方式及注意事项。Redis凭借其高性能、丰富的数据结构、数据持久化和分布式支持等特点,在提升应用响应速度和处理能力方面表现突出
本文深入探讨了Redis作为PHP缓存解决方案的优势、实现方式及注意事项。Redis凭借其高性能、丰富的数据结构、数据持久化和分布式支持等特点,在提升应用响应速度和处理能力方面表现突出。文章还介绍了Redis在页面缓存、数据缓存和会话缓存等应用场景中的使用,并强调了缓存数据一致性、过期时间设置、容量控制和安全问题的重要性。
73 5
|
4月前
|
NoSQL MongoDB PHP
PHP7 MongDB 安装与使用
10月更文挑战第19天
60 1
PHP7 MongDB 安装与使用
|
4月前
|
缓存 资源调度 持续交付
在清空NPM缓存后,我如何检查是否所有依赖都已正确安装?
【10月更文挑战第5天】在清空NPM缓存后,我如何检查是否所有依赖都已正确安装?
|
4月前
|
测试技术 PHP 开发工具
php性能监测模块XHProf安装与测试
【10月更文挑战第13天】php性能监测模块XHProf安装与测试
53 0
|
4月前
|
缓存 PHP C语言
宝塔PHP8.1安装fileinfo拓展失败解决办法
在宝塔面板安装PHP8.1后,fileinfo扩展安装失败,手动尝试也报错。通过分析错误信息,在Makefile中修改CFLAGS添加`-std=c99`,并执行`make clean`清除缓存后,重新编译安装成功。最后在php.ini中启用fileinfo扩展并重启PHP服务。注意需调整CFLAGS为`-std=c99 -g`,去掉`-O2`。
347 0
|
13天前
|
关系型数据库 MySQL 网络安全
如何排查和解决PHP连接数据库MYSQL失败写锁的问题
通过本文的介绍,您可以系统地了解如何排查和解决PHP连接MySQL数据库失败及写锁问题。通过检查配置、确保服务启动、调整防火墙设置和用户权限,以及识别和解决长时间运行的事务和死锁问题,可以有效地保障应用的稳定运行。
67 25
|
3月前
|
前端开发 关系型数据库 MySQL
PHP与MySQL动态网站开发实战指南####
【10月更文挑战第21天】 本文将深入浅出地探讨如何使用PHP与MySQL构建一个动态网站,从环境搭建到项目部署,全程实战演示。无论你是编程新手还是希望巩固Web开发技能的老手,都能在这篇文章中找到实用的技巧和启发。我们将一起探索如何通过PHP处理用户请求,利用MySQL存储数据,并最终呈现动态内容给用户,打造属于自己的在线平台。 ####
131 0

热门文章

最新文章