ab测试
装apache 的AB
1ubuntu安装AB:
`sudo apt-get install apache2-utils`
2.centos安装ab:
yum -y install httpd-tools
安装后就可以开始测试
1.硬件:阿里云机器,1核cpu,4g内存(上面有很多其他的网站应用,因此可以看成3G的内存)
2.php-fpm
pm = dynamic
pm.max_children = 20
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 20
3.阿里云上面还有其他的一些站点,另外还开了一个php5.4,因此资源虽然是4G,但是用于测试的可能3G内存都不到
4.用于测试的url
4.1:在controller部分直接返回数据的url
, http://fecshop.appfront.fancyecommerce.com/customer/test/test
public function actionTest(){
echo 12;exit;
}
这个相当于测试框架
的性能
,也就是框架初始化
带来的时间消耗
,用这个和fecmall添加逻辑
后的时间消耗
做对比
4.2:fecshop appfront部分的产品链接:http://fecshop.appfront.fancyecommerce.com/alluring-long-sleeve-open-back-draped-maxi-dress-55525232
5.以上测试是本地测试,没有网络开销
5.1在/etc/hosts中做了指向,http://fecshop.appfront.fancyecommerce.com
指向127.0.0.1
,这样不会由网络开销
5.2Apache AB
和fecmall
,都是在同一台机器上面,Apache AB
也会耗费
一定的资源
测试1
php.ini没有开启opcache
,fecshop没有开启缓存
1.测试一下初始化:http://fecshop.appfront.fancyecommerce.com/customer/test/test
(这个url在controller中进行输出后,直接exit)
[root@iZ942k2d5ezZ ~]# ab -n 50 -c 10 http://fecshop.appfront.fancyecommerce.com/customer/test/test
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking fecshop.appfront.fancyecommerce.com (be patient).....done
Server Software: nginx
Server Hostname: fecshop.appfront.fancyecommerce.com
Server Port: 80
Document Path: /customer/test/test
Document Length: 2 bytes
Concurrency Level: 10
Time taken for tests: 3.579 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 18150 bytes
HTML transferred: 100 bytes
Requests per second: 13.97 [#/sec] (mean)
Time per request: 715.731 [ms] (mean)
Time per request: 71.573 [ms] (mean, across all concurrent requests)
Transfer rate: 4.95 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 56 682 111.5 692 842
Waiting: 51 680 112.7 692 842
Total: 57 682 111.4 692 842
Percentage of the requests served within a certain time (ms)
50% 692
66% 713
75% 731
80% 758
90% 781
95% 818
98% 842
99% 842
100% 842 (longest request)
结果:13.97 [#/sec]
2.
ab -n 50 -c 10 http://fecshop.appfront.fancyecommerce.com/alluring-long-sleeve-open-back-draped-maxi-dress-55525232
结果:
[root@iZ942k2d5ezZ ~]# ab -n 50 -c 10 http://fecshop.appfront.fancyecommerce.com/alluring-long-sleeve-open-back-draped-maxi-dress-55525232
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking fecshop.appfront.fancyecommerce.com (be patient).....done
Server Software: nginx
Server Hostname: fecshop.appfront.fancyecommerce.com
Server Port: 80
Document Path: /alluring-long-sleeve-open-back-draped-maxi-dress-55525232
Document Length: 78750 bytes
Concurrency Level: 10
Time taken for tests: 7.959 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 3960848 bytes
HTML transferred: 3937500 bytes
Requests per second: 6.28 [#/sec] (mean)
Time per request: 1591.726 [ms] (mean)
Time per request: 159.173 [ms] (mean, across all concurrent requests)
Transfer rate: 486.02 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 335 1517 188.8 1560 1690
Waiting: 243 1440 188.9 1495 1603
Total: 335 1517 188.8 1560 1690
Percentage of the requests served within a certain time (ms)
50% 1560
66% 1597
75% 1604
80% 1615
90% 1640
95% 1649
98% 1690
99% 1690
100% 1690 (longest request)
结果:6.28 [#/sec]
可以看到,不做任何优化,性能是很差的
测试2,开启opcache
[opcache]
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.file_cache=/tmp
1.ab测试ab -n 50 -c 10 http://fecshop.appfront.fancyecommerce.com/customer/test/test
[root@iZ942k2d5ezZ ~]# ab -n 50 -c 10 http://fecshop.appfront.fancyecommerce.com/customer/test/test
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking fecshop.appfront.fancyecommerce.com (be patient).....done
Server Software: nginx
Server Hostname: fecshop.appfront.fancyecommerce.com
Server Port: 80
Document Path: /customer/test/test
Document Length: 2 bytes
Concurrency Level: 10
Time taken for tests: 0.372 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 18150 bytes
HTML transferred: 100 bytes
Requests per second: 134.48 [#/sec] (mean)
Time per request: 74.363 [ms] (mean)
Time per request: 7.436 [ms] (mean, across all concurrent requests)
Transfer rate: 47.67 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 8 70 17.2 74 94
Waiting: 5 70 17.4 74 94
Total: 8 70 17.2 74 94
Percentage of the requests served within a certain time (ms)
50% 74
66% 80
75% 83
80% 84
90% 88
95% 90
98% 94
99% 94
100% 94 (longest request)
结果:134.48 [#/sec]
,可以看到开启apc后,从
13.97 [#/sec]
提升了近10倍的速度
2.
ab -n 50 -c 10 http://fecshop.appfront.fancyecommerce.com/alluring-long-sleeve-open-back-draped-maxi-dress-55525232
[root@iZ942k2d5ezZ ~]# ab -n 50 -c 10 http://fecshop.appfront.fancyecommerce.com/alluring-long-sleeve-open-back-draped-maxi-dress-55525232
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking fecshop.appfront.fancyecommerce.com (be patient).....done
Server Software: nginx
Server Hostname: fecshop.appfront.fancyecommerce.com
Server Port: 80
Document Path: /alluring-long-sleeve-open-back-draped-maxi-dress-55525232
Document Length: 78750 bytes
Concurrency Level: 10
Time taken for tests: 3.381 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 3960749 bytes
HTML transferred: 3937500 bytes
Requests per second: 14.79 [#/sec] (mean)
Time per request: 676.257 [ms] (mean)
Time per request: 67.626 [ms] (mean, across all concurrent requests)
Transfer rate: 1143.92 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 153 634 131.1 642 894
Waiting: 79 580 128.1 585 843
Total: 153 634 131.1 642 894
Percentage of the requests served within a certain time (ms)
50% 642
66% 678
75% 689
80% 710
90% 846
95% 852
98% 894
99% 894
100% 894 (longest request)
[root@iZ942k2d5ezZ ~]#
14.79 [#/sec]
由6.28 [#/sec]
到14.79 [#/sec]
,产品页面的速度提升了一倍左右,但是还是并发不高
测试3
开启cache: @appfront/config/fecshop_local_services/Cache.php
设置enable 为 true
[root@iZ942k2d5ezZ ~]# ab -n 50 -c 10 http://fecshop.appfront.fancyecommerce.com/alluring-long-sleeve-open-back-draped-maxi-dress-55525232
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking fecshop.appfront.fancyecommerce.com (be patient).....done
Server Software: nginx
Server Hostname: fecshop.appfront.fancyecommerce.com
Server Port: 80
Document Path: /alluring-long-sleeve-open-back-draped-maxi-dress-55525232
Document Length: 78750 bytes
Concurrency Level: 10
Time taken for tests: 0.510 seconds
Complete requests: 50
Failed requests: 0
Write errors: 0
Total transferred: 3960700 bytes
HTML transferred: 3937500 bytes
Requests per second: 98.00 [#/sec] (mean)
Time per request: 102.046 [ms] (mean)
Time per request: 10.205 [ms] (mean, across all concurrent requests)
Transfer rate: 7580.67 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 0
Processing: 51 99 17.8 102 131
Waiting: 9 66 13.1 66 85
Total: 51 99 17.9 102 131
Percentage of the requests served within a certain time (ms)
50% 102
66% 108
75% 111
80% 112
90% 122
95% 128
98% 131
99% 131
100% 131 (longest request)
结果:98.00 [#/sec]
开启整页缓存后,效果还是很明显的,产品页面秒并发98
测试4 appserver这种api端
1.没有开启缓存
[root@iZ942k2d5ezZ ~]# ab -n 100 -c 10 http://fecshop.appserver.fancyecommerce.com/catalog/product/index?product_id=57c3aaa9f656f24f353bf56e
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking fecshop.appserver.fancyecommerce.com (be patient).....done
Server Software: nginx
Server Hostname: fecshop.appserver.fancyecommerce.com
Server Port: 80
Document Path: /catalog/product/index?product_id=57c3aaa9f656f24f353bf56e
Document Length: 4296 bytes
Concurrency Level: 10
Time taken for tests: 3.858 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 460100 bytes
HTML transferred: 429600 bytes
Requests per second: 25.92 [#/sec] (mean)
Time per request: 385.761 [ms] (mean)
Time per request: 38.576 [ms] (mean, across all concurrent requests)
Transfer rate: 116.48 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 11 100.0 0 1000
Processing: 13 286 341.0 215 3075
Waiting: 13 209 171.9 158 1467
Total: 13 296 347.4 238 3075
Percentage of the requests served within a certain time (ms)
50% 238
66% 278
75% 304
80% 327
90% 632
95% 734
98% 1456
99% 3075
100% 3075 (longest request)
结果为:25.92 [#/sec]
2.appserver 开启cache
开启cache: @appserver/config/fecshop_local_services/Cache.php
设置enable
为 true
,如果没有这个文件,将@appfront/config/fecshop_local_services/Cache.php
复制过去,然后设置enable
为 true
注意,更改文件要重启下php,因为开启了opcache
[root@iZ942k2d5ezZ ~]# ab -n 100 -c 10 http://fecshop.appserver.fancyecommerce.com/catalog/product/index?product_id=57c3aaa9f656f24f353bf56e
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking fecshop.appserver.fancyecommerce.com (be patient).....done
Server Software: nginx
Server Hostname: fecshop.appserver.fancyecommerce.com
Server Port: 80
Document Path: /catalog/product/index?product_id=57c3aaa9f656f24f353bf56e
Document Length: 1974 bytes
Concurrency Level: 10
Time taken for tests: 1.105 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Total transferred: 212900 bytes
HTML transferred: 197400 bytes
Requests per second: 98.52 [#/sec] (mean)
Time per request: 110.475 [ms] (mean)
Time per request: 11.048 [ms] (mean, across all concurrent requests)
Transfer rate: 188.20 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 1
Processing: 9 99 46.2 86 283
Waiting: 9 96 44.1 86 283
Total: 10 99 46.1 86 283
Percentage of the requests served within a certain time (ms)
50% 86
66% 89
75% 92
80% 94
90% 179
95% 233
98% 277
99% 283
100% 283 (longest request)
可以看到速度提升到了98.52 [#/sec]
,开启cache,访问产品分类,速度提升还是很明显的。
总结:
php7.1, 1核3G的内存下。
1.Yii2框架,在开启opcache后,有一个质的提升,大约10倍的速度提升
2.fecshop可以通过开启opcache 和 fecshop缓存,,达到100.00 [#/sec]
的并发
3.对于自己开发的一些api,也尽量的加缓存,增强并发
4.如果是线上服务器压测,因为有网络开销,像阿里云还有流量的限制,因此需要走内网测试,可以通过hosts,将访问的域名映射到127.0.0.1,然后在本机进行ab测试,譬如我添加的
vim /etc/hosts
127.0.0.1 localhost xunsearch elasticsearch1 fecshop.appfront.fancyecommerce.com fecshop.appserver.fancyecommerce.com
访问 fecshop.appserver.fancyecommerce.com 直接走本机,不走外部网络。
5.本部分只对开启opcache 和 fecshop缓存 后的并发数进行测试,而且是1核3G内存进行的测试,如果您的机器内存高,cpu数量多,可以多开php-fpm, 并发数会更高
6.其他的更多的性能提速的文档,参看:http://www.fecshop.com/doc/fecshop-guide/instructions/cn-1.0/guide-fecshop_online_speed.html