您的位置:首页 > 其它

013-LAMP_enchance concurrency

2016-01-21 11:53 459 查看

013-LAMP_enchance concurrency

测试静态页面并发访问

This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ 
Benchmarking 192.168.200.137 (be patient)

Server Software:        Apache/2.4.6
Server Hostname:        192.168.200.137
Server Port:            80

Document Path:          /index.html
Document Length:        21 bytes

Concurrency Level:      100
Time taken for tests:   0.165 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      281000 bytes
HTML transferred:       21000 bytes
Requests per second:    6071.98 [#/sec] (mean)
Time per request:       16.469 [ms] (mean)
Time per request:       0.165 [ms] (mean, across all concurrent requests)
Transfer rate:          1666.24 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0    2   2.5      1      12
Processing:     5   14   2.6     14      23
Waiting:        5   14   2.7     13      22
Total:          7   15   2.8     15      23

Percentage of the requests served within a certain time (ms)
50%     15
66%     16
75%     17
80%     18
90%     20
95%     21
98%     21
99%     23
100%     23 (longest request)


测试动态资源并发访问

This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ 
Benchmarking 192.168.200.137 (be patient)

Server Software:        Apache/2.4.6
Server Hostname:        192.168.200.137
Server Port:            80

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

Concurrency Level:      100
Time taken for tests:   0.799 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      179000 bytes
HTML transferred:       7000 bytes
Requests per second:    1252.13 [#/sec] (mean)
Time per request:       79.864 [ms] (mean)
Time per request:       0.799 [ms] (mean, across all concurrent requests)
Transfer rate:          218.88 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0    0   0.6      0       5
Processing:     7   76  15.9     75     122
Waiting:        7   76  15.9     75     122
Total:          8   76  15.8     76     122

Percentage of the requests served within a certain time (ms)
50%     76
66%     81
75%     85
80%     88
90%     98
95%    102
98%    105
99%    110
100%    122 (longest request)


apache benchmark fields explanation

Benchmarking 192.168.200.137 (be patient)   #表示正在向192.168.200.137测试
Server Software:        Apache/2.4.6        #表示web server的类型
Server Hostname:        192.168.200.137     #表示server的IP
Server Port:            80                  #表示测试的端口

Document Path:          /index.php          #表示资源的路径
Document Length:        7 bytes             #表示资源的大小

Concurrency Level:      100                 #表示并发级别,即每秒100个请求
Time taken for tests:   0.799 seconds       #表示测试的时长
Complete requests:      1000                #表示请求的数量,一共1000个
Failed requests:        0                   #表示失败的请求个数
Total transferred:      179000 bytes        #表示总传输字节,这里包括各种header等
HTML transferred:       7000 bytes          #表示仅仅是资源的总大小
Requests per second:    1252.13 [#/sec] (mean)  #表示平均每秒的可以处理的请求数量
Time per request:       79.864 [ms] (mean)      #表示平均每次并发的处理时长
Time per request:       0.799 [ms] (mean, across all concurrent requests)   #表示平均每条请求的处理时长
Transfer rate:          218.88 [Kbytes/sec] received    #表示传输速率

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0    0   0.6      0       5             #表示连接时长
Processing:     7   76  15.9     75     122             #表示处理时长
Waiting:        7   76  15.9     75     122             #表示等待时长
Total:          8   76  15.8     76     122             #表示总的消耗时长

Percentage of the requests served within a certain time (ms)    #表示#ms响应的百分比
50%     76
66%     81
75%     85
80%     88
90%     98
95%    102
98%    105
99%    110
100%    122 (longest request)


从静态及动态测试中可以看出静态页面的响应速度明显比动态资源快!

xchahe

[root@husa php]# yum install php-xcache
xcache位于epel源
php-xcache                    x86_64                    3.1.1-1.el7
c5fc
epel                     72 k


查看xcache生成的各种文件

[root@husa php]# rpm -ql php-xcache
/etc/php.d/xcache.ini
/usr/lib64/php/modules/xcache.so
/usr/share/doc/php-xcache-3.1.1
/usr/share/doc/php-xcache-3.1.1/AUTHORS
/usr/share/doc/php-xcache-3.1.1/COPYING
/usr/share/doc/php-xcache-3.1.1/ChangeLog
/usr/share/doc/php-xcache-3.1.1/README
/usr/share/doc/php-xcache-3.1.1/THANKS


xcache配置文件

/etc/php.d/xcache.ini


[xcache.admin]
xcache.admin.enable_auth = On       #表示是否启用xcache
xcache.admin.user = "mOo"           #表示xcache的admin的用户名
xcache.admin.pass = "md5 encrypted password"    #表示xcache的admin的用户密码
xcache.size  =               60M    #表示xcache的缓存大小
xcache.ttl   =                 0    #表示xcache的缓存生命时长,0表示forever


配置xcache生效

直接reload php-fpm

[root@husa php.d]# systemctl reload php-fpm


配置xcache之后的动态资源请求结果

[husa@ArchLinux-husa ~]$ ab -n 1000 -c 100 http://192.168.200.137/index.php This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ 
Benchmarking 192.168.200.137 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software:        Apache/2.4.6
Server Hostname:        192.168.200.137
Server Port:            80

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

Concurrency Level:      100
Time taken for tests:   0.625 seconds
Complete requests:      1000
Failed requests:        0
Total transferred:      179000 bytes
HTML transferred:       7000 bytes
Requests per second:    1600.62 [#/sec] (mean)
Time per request:       62.476 [ms] (mean)
Time per request:       0.625 [ms] (mean, across all concurrent requests)
Transfer rate:          279.80 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0    1   2.9      0      14
Processing:    15   58   8.4     58      96
Waiting:       15   58   8.4     58      96
Total:         29   59   6.9     59      96

Percentage of the requests served within a certain time (ms)
50%     59
66%     61
75%     63
80%     64
90%     67
95%     70
98%     74
99%     78
100%     96 (longest request)


可以发现总的时长减少了大约0.3毫秒

编译安装xcache

编译安装php扩展

1、安装php-devel

[root@husa php.d]# systemctl reload php-fpm


2、下载xcache

[root@husa ~]# ls
99.sh  anaconda-ks.cfg  a.sh  grub.bak  linux-3.10.67.tar.xz  pma  scp.txt  service.sh  show.sh  xcache-3.2.0.tar.bz2
[root@husa ~]# tar xjf xcache-3.2.0.tar.bz2
[root@husa ~]# ls
99.sh            a.sh      linux-3.10.67.tar.xz  scp.txt     show.sh       xcache-3.2.0.tar.bz2
anaconda-ks.cfg  grub.bak  pma                   service.sh  xcache-3.2.0


3、在源代码目录中运行phpize命令

phpize - prepare a PHP extension for compiling
这个命令是用来为PHP编译安装扩展的


4、配置编译脚本然后编译安装

/configure --enable-xcache --with-php-config=/usr/bin/php-config
[root@husa xcache-3.2.0]# make -j 2 && make install


–enable-xcache表示编译安装之后直接启用xcache,with-php-config表示提供php的配置文件给php-xcache

5、把源代码目录中的xcache.ini配置文件放置到/etc/php.d目录中然后进行相应的配置

[root@husa xcache-3.2.0]# cp xcache.ini /etc/php.d/


6、重载php-fpm

[root@husa php.d]# systemctl reload php-fpm


7、压力测试

注意:本地测试没有考虑带宽,因此要远程测试
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: