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 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、壓力測試
注意:本地測試沒有考慮帶寬,因此要遠程測試