linapex的gravatar头像
linapex 2014-10-14 15:37:30

开发者如何对web项目做性能测试?

在实际项目开发中,大家的对于项目的性能是如何测试的?

常用的服务器:jetty,tomcat,jboss,welogic

常用的测试手段:apache ab,jmeter,loadrunner

 

如何评估一个项目能够承载百万级,千万级,亿万级的访问量呢。临界点在哪?

开发者如何对web项目做性能测试?

所有回答列表(2)
最代码官方的gravatar头像
最代码官方  LV168 2014年10月14日

软件性能测试需要在已知的硬件配置和软件参数配置下测试才有意义。

最代码的服务器是单核,2g内存

tomcat中jvm参数配置:

JAVA_OPTS="$JAVA_OPTS -server -Xms256m -Xmx1024m -XX:NewSize=128m -XX:MaxNewSize=128m -XX:PermSize=128m -XX:MaxPermSize=128m     -XX:+DisableExplicitGC"

运行结果:

[root@AY131127173600769912Z local]# ab -c 20 -t 10 "http://www.zuidaima.com/"
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.zuidaima.com (be patient)
Finished 11 requests


Server Software:        nginx/1.5.6
Server Hostname:        www.zuidaima.com
Server Port:            80

Document Path:          /
Document Length:        116427 bytes

Concurrency Level:      20
Time taken for tests:   10.171361 seconds
Complete requests:      11
Failed requests:        0
Write errors:           0
Total transferred:      1348923 bytes
HTML transferred:       1346007 bytes
Requests per second:    1.08 [#/sec] (mean)
Time per request:       18493.384 [ms] (mean)
Time per request:       924.669 [ms] (mean, across all concurrent requests)
Transfer rate:          129.48 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0 1385 769.3   1872    1872
Processing:   531 5231 2627.5   6643    7185
Waiting:        0 4918 2838.6   6338    7040
Total:       1872 6616 3102.1   8515    9057

Percentage of the requests served within a certain time (ms)
  50%   8515
  66%   8523
  75%   8740
  80%   8740
  90%   8877
  95%   9057
  98%   9057
  99%   9057
 100%   9057 (longest request)

top截图:

开发者如何对web项目做性能测试?

cpu已经飙到90%,响应时间50%以上8秒显然是不可接受的,所以需要在软件上做优化,当然最简单的就是升级硬件。

2014-10-24 18:00测试结果

增加ehcache机制后,同样的命令执行后截图:

[root@AY131127173600769912Z ~]# ab -c 20 -t 10 "http://www.zuidaima.com/"
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.zuidaima.com (be patient)
Finished 136 requests


Server Software:        nginx/1.5.6
Server Hostname:        www.zuidaima.com
Server Port:            80

Document Path:          /
Document Length:        125049 bytes

Concurrency Level:      20
Time taken for tests:   10.12944 seconds
Complete requests:      136
Failed requests:        0
Write errors:           0
Total transferred:      17162626 bytes
HTML transferred:       17128849 bytes
Requests per second:    13.58 [#/sec] (mean)
Time per request:       1472.492 [ms] (mean)
Time per request:       73.625 [ms] (mean, across all concurrent requests)
Transfer rate:          1673.83 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    8  21.9      0      63
Processing:    56 1299 1285.2    874    8971
Waiting:        0 1127 1169.9    637    8769
Total:         56 1308 1296.5    874    9034

Percentage of the requests served within a certain time (ms)
  50%    874
  66%   1512
  75%   1768
  80%   2054
  90%   2746
  95%   4145
  98%   5087
  99%   5682
 100%   9034 (longest request)

可以看到性能比原先提高了不少,接下来还会继续优化。起码从软件层做到性能最大化。

2015-12-9 13:40测试结果

双核,2G内存,tomcat server.xml修改配置

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
	<Listener className="org.apache.catalina.core.JasperListener"/>
	<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
	<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
	<Service name="Catalina">
		<Executor maxThreads="500" minSpareThreads="4" name="tomcatThreadPool" namePrefix="catalina-exec-"/>
		<Connector URIEncoding="UTF-8" connectionTimeout="20000" executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
		<Engine defaultHost="localhost" name="Catalina">
			<Host name="localhost"
            xmlValidation="false" xmlNamespaceAware="false">
	      <Context docBase="/data/www/www.zuidaima.com_8080" path="/" disableURLRewriting="true" sessionCookieName="zdmid"/>
	</Host>
		</Engine>
	</Service>
</Server>
[root@AY131127173600769912Z ~]# ab -t 10 -c 20 "http://www.zuidaima.com/"
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.zuidaima.com (be patient)
Finished 116 requests


Server Software:        nginx/1.5.6
Server Hostname:        www.zuidaima.com
Server Port:            80

Document Path:          /
Document Length:        110272 bytes

Concurrency Level:      20
Time taken for tests:   10.34452 seconds
Complete requests:      116
Failed requests:        97
   (Connect: 0, Length: 97, Exceptions: 0)
Write errors:           0
Total transferred:      12885678 bytes
HTML transferred:       12857004 bytes
Requests per second:    11.56 [#/sec] (mean)
Time per request:       1730.078 [ms] (mean)
Time per request:       86.504 [ms] (mean, across all concurrent requests)
Transfer rate:          1253.98 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   3.0      0      11
Processing:   482 1658 1255.6   1049    4221
Waiting:      472 1614 1263.7    975    4193
Total:        482 1659 1256.4   1049    4222

Percentage of the requests served within a certain time (ms)
  50%   1049
  66%   2017
  75%   2031
  80%   2031
  90%   4219
  95%   4220
  98%   4222
  99%   4222
 100%   4222 (longest request)

2015-12-14 18:57测试结果

将动态列表的id采用redis查询机制后的测试结果

[root@AY131127173600769912Z ~]# ab -t 10 -c 20 "http://www.zuidaima.com/"
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.zuidaima.com (be patient)
Finished 187 requests


Server Software:        nginx/1.5.6
Server Hostname:        www.zuidaima.com
Server Port:            80

Document Path:          /
Document Length:        92916 bytes

Concurrency Level:      20
Time taken for tests:   10.57819 seconds
Complete requests:      187
Failed requests:        0
Write errors:           0
Total transferred:      17428925 bytes
HTML transferred:       17383241 bytes
Requests per second:    18.59 [#/sec] (mean)
Time per request:       1075.703 [ms] (mean)
Time per request:       53.785 [ms] (mean, across all concurrent requests)
Transfer rate:          1692.22 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       1
Processing:   260 1038 535.8    961    6218
Waiting:      225  987 536.5    916    6217
Total:        260 1038 535.9    961    6219

Percentage of the requests served within a certain time (ms)
  50%    959
  66%   1116
  75%   1220
  80%   1255
  90%   1514
  95%   1732
  98%   2194
  99%   2470
 100%   6219 (longest request)

感觉性能变化不大,期待后续的优化。

加一个100并发的测试用例,为以后优化有个参考:

[root@AY131127173600769912Z ~]# ab -t 10 -c 100 "http://www.zuidaima.com/"
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.zuidaima.com (be patient)
Finished 126 requests


Server Software:        nginx/1.5.6
Server Hostname:        www.zuidaima.com
Server Port:            80

Document Path:          /
Document Length:        95415 bytes

Concurrency Level:      100
Time taken for tests:   10.20080 seconds
Complete requests:      126
Failed requests:        0
Write errors:           0
Total transferred:      12118461 bytes
HTML transferred:       12087357 bytes
Requests per second:    12.57 [#/sec] (mean)
Time per request:       7952.444 [ms] (mean)
Time per request:       79.524 [ms] (mean, across all concurrent requests)
Transfer rate:          1181.03 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   10  11.3      3      26
Processing:  1812 3970 1323.1   3777    8118
Waiting:     1724 3912 1317.0   3700    8117
Total:       1812 3981 1324.4   3799    8121

Percentage of the requests served within a certain time (ms)
  50%   3799
  66%   4518
  75%   4793
  80%   4934
  90%   5868
  95%   6512
  98%   7101
  99%   7380
 100%   8121 (longest request)
aide_941的gravatar头像
aide_941  LV9 2015年11月3日
试试
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友