标签:copyright wordpress specified software 压力测试 ab
前面介绍到了3个应用的安装,接下来是对其中一个应用做压力测试,后用xcache提供php加速功能,再来测试一下性能提升了多少,而后把mysql分离出来,做压测看能否提升性能。
1.对wordpress做压力测试
[root@smallpc ~]# ab -c 100 -n 1000 http://192.168.20.163/wordpress/index.php
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 192.168.20.163 (be patient)
apr_poll: The timeout specified has expired (70007)
Total of 18 requests completed 由于是虚拟机,这里只完成了18个请求
查看服务器状态页面时,显示
此时终端都卡住了,页面也访问不了
[root@localhost wordpress]# free -m
total used free shared buffers cached
Mem: 482 467 15 0 0 12
-/+ buffers/cache: 454 28
Swap: 1535 1014 521 内存占满了
[root@smallpc ~]# ab -c 80 -n 500 http://192.168.20.163/wordpress/index.php
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 192.168.20.163 (be patient)
apr_poll: The timeout specified has expired (70007)
虚拟机都挂了,看了要换实体机来实验了,先凑合着用
登录项没有任何反应,重启虚拟机,发现虚拟机只有512M的内存,给其2G内存,再来实验
[root@localhost ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 50 *:3306 *:*
LISTEN 0 128 :::8080 :::*
LISTEN 0 128 :::80 :::*
[root@localhost ~]# ps aux | grep httpd
root 5553 0.1 0.5 256772 9652 ? Ss 01:50 0:00 /usr/sbin/httpd
apache 5602 0.0 0.2 256772 5516 ? S 01:50 0:00 /usr/sbin/httpd
apache 5603 0.0 0.2 256772 5512 ? S 01:50 0:00 /usr/sbin/httpd
apache 5604 0.0 0.2 256772 5512 ? S 01:50 0:00 /usr/sbin/httpd
apache 5605 0.0 0.2 256772 5512 ? S 01:50 0:00 /usr/sbin/httpd
apache 5606 0.0 0.2 256772 5512 ? S 01:50 0:00 /usr/sbin/httpd
apache 5607 0.0 0.2 256772 5512 ? S 01:50 0:00 /usr/sbin/httpd
apache 5608 0.0 0.2 256772 5512 ? S 01:50 0:00 /usr/sbin/httpd
apache 5609 0.0 0.2 256772 5512 ? S 01:50 0:00 /usr/sbin/httpd
root 5635 0.0 0.0 103252 840 pts/0 S+ 01:51 0:00 grep httpd
此时是prefork模型工作,修改一下配置文件
<IfModule prefork.c>
StartServers 8 改为 15
MinSpareServers 5
MaxSpareServers 20 改为45
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
[root@localhost ~]# service httpd reload
Reloading httpd:
[root@hostpc ~]# ulimit -n 5000
发起压力测试:
[root@hostpc ~]# ab -c 100 -n 1000 http://192.168.20.163/wordpress/index.php
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 192.168.20.163 (be patient)
apr_poll: The timeout specified has expired (70007)
Total of 30 requests completed
服务器挂了,只能等待了
其中载录了一种状态
都是一些等待连接
交换内存已经使用了234M了
此时只有等 等待连接处理完才能,内存才会降下来
[root@localhost ~]# top
top - 03:41:17 up 1:51, 3 users, load average: 0.00, 0.09, 1.35
Tasks: 167 total, 1 running, 166 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 0.0%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1914428k total, 1240172k used, 674256k free, 20808k buffers
Swap: 1572860k total, 43992k used, 1528868k free, 199596k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
5769 apache 20 0 272m 26m 4440 S 0.0 1.4 0:03.30 httpd
6249 apache 20 0 364m 25m 4860 S 0.0 1.4 0:01.43 httpd
5930 apache 20 0 364m 25m 4976 S 0.0 1.4 0:02.59 httpd
6247 apache 20 0 269m 25m 4792 S 0.0 1.4 0:01.25 httpd
5879 apache 20 0 364m 25m 4928 S 0.0 1.4 0:02.20 httpd
5892 apache 20 0 364m 25m 4924 S 0.0 1.3 0:02.33 httpd
5924 apache 20 0 364m 25m 4936 S 0.0 1.3 0:03.16 httpd
5888 apache 20 0 364m 25m 4888 S 0.0 1.3 0:02.49 httpd
5808 apache 20 0 364m 25m 4892 S 0.0 1.3 0:02.62 httpd
5820 apache 20 0 269m 25m 4780 S 0.0 1.3 0:02.51 httpd
5839 apache 20 0 269m 25m 4780 S 0.0 1.3 0:02.51 httpd
5868 apache 20 0 269m 25m 4780 S 0.0 1.3 0:02.03 httpd
5827 apache 20 0 269m 25m 4780 S 0.0 1.3 0:02.42 httpd
5777 apache 20 0 364m 25m 4740 S 0.0 1.3 0:02.70 httpd
5823 apache 20 0 269m 25m 4780 S 0.0 1.3 0:02.50 httpd
5899 apache 20 0 364m 24m 4668 S 0.0 1.3 0:02.35 httpd
现在可以发现cpu负载都很小了,只有一个处于运行状态,166个进程都是睡眠状态,因为刚才发了好几个并发请求,cpu是有记忆功能的,这种状态会保持一段时间,httpd启动的进程数也为最大空闲进程数。
[root@localhost wordpress]# free -m
total used free shared buffers cached
Mem: 1869 1244 624 0 22 217
-/+ buffers/cache: 1004 865
Swap: 1535 42 1493
[root@localhost wordpress]# echo 1 > /proc/sys/vm/drop_caches 清空缓存
[root@localhost wordpress]# free -m
total used free shared buffers cached
Mem: 1869 1016 853 0 0 14
-/+ buffers/cache: 1001 868 这是空闲的内存变大了,cached和buffers都变小了
Swap: 1535 42 1493
[root@hostpc ~]# ab -c 20 -n 500 http://192.168.20.163/wordpress/index.php
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 192.168.20.163 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests
Server Software: Apache
Server Hostname: 192.168.20.163
Server Port: 80
Document Path: /wordpress/index.php
Document Length: 0 bytes
Concurrency Level: 20
Time taken for tests: 124.706 seconds
Complete requests: 500
Failed requests: 0
Write errors: 0
Non-2xx responses: 500
Total transferred: 155000 bytes
HTML transferred: 0 bytes
Requests per second: 4.01 [#/sec] (mean)
Time per request: 4988.240 [ms] (mean)
Time per request: 249.412 [ms] (mean, across all concurrent requests)
Transfer rate: 1.21 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 35 181.4 1 1002
Processing: 1058 4936 2553.0 3931 14696
Waiting: 1058 4919 2551.4 3920 14695
Total: 1059 4971 2549.4 3933 14697
Percentage of the requests served within a certain time (ms)
50% 3933
66% 4296
75% 5303
80% 6077
90% 8435
95% 11511
98% 13257
99% 14583
100% 14697 (longest request)
安装xcache
#yum install -y php-xcache
查看安装生成了哪些文件
#rpm -ql php-xcache
重启一下httpd
[root@localhost ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain for ServerName
[root@localhost ~]# ps aux | grep httpd
root 9418 2.8 0.5 324584 10080 ? Ss 07:04 0:01 /usr/sbin/httpd
apache 9421 0.2 0.3 324944 6528 ? S 07:04 0:00 /usr/sbin/httpd
apache 9422 0.1 0.3 324944 6528 ? S 07:04 0:00 /usr/sbin/httpd
apache 9423 0.1 0.2 324584 5592 ? S 07:04 0:00 /usr/sbin/httpd
apache 9424 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
apache 9425 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
apache 9426 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
apache 9427 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
apache 9428 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
apache 9429 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
apache 9430 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
apache 9431 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
apache 9432 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
apache 9433 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
apache 9434 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
apache 9435 0.0 0.2 324584 5588 ? S 07:04 0:00 /usr/sbin/httpd
root 9437 0.0 0.0 103252 828 pts/2 S+ 07:05 0:00 grep httpd
[root@localhost ~]# free -m
total used free shared buffers cached
Mem: 1869 243 1625 0 5 101
-/+ buffers/cache: 136 1732 这是空闲内存已经有好多了
Swap: 1535 22 1513
再发起一次压测
[root@hostpc ~]# ab -c 20 -n 500 http://192.168.20.163/wordpress/index.php
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 192.168.20.163 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Finished 500 requests
Server Software: Apache
Server Hostname: 192.168.20.163
Server Port: 80
Document Path: /wordpress/index.php
Document Length: 0 bytes
Concurrency Level: 20
Time taken for tests: 109.287 seconds
Complete requests: 500
Failed requests: 0
Write errors: 0
Non-2xx responses: 500
Total transferred: 155000 bytes
HTML transferred: 0 bytes
Requests per second: 4.58 [#/sec] (mean)
Time per request: 4371.464 [ms] (mean)
Time per request: 218.573 [ms] (mean, across all concurrent requests)
Transfer rate: 1.39 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 1.7 1 19
Processing: 232 4215 4474.5 4897 20757
Waiting: 232 4203 4472.0 4892 20757
Total: 234 4217 4474.7 4898 20758
Percentage of the requests served within a certain time (ms)
50% 4898
66% 5518
75% 5645
80% 5751
90% 10529
95% 11134
98% 20599
99% 20640
100% 20758 (longest request) [ OK ]
可以发现性能也没提升多少,因为本身是虚拟机而且内存又不大,所以性能提升也不明显
把MySQL分离出去,就是要请求数据时需要远程来请求访问,需要提供用户远程MySQL服务器来登录获取数据,此处就不演示了,因为前面应用中也有指定过mysql的位置,只要把MySQL改为远程提供服务,且授权到用户使用指定的数据库即可。
本文出自 “快乐就好” 博客,请务必保留此出处http://wdllife.blog.51cto.com/6615958/1622573
标签:copyright wordpress specified software 压力测试 ab
原文地址:http://wdllife.blog.51cto.com/6615958/1622573