编辑推荐: |
本文来自于infoq,jmeter是apache公司基于java开发的一款开源压力测试工具,体积小,功能全,使用方便,是一个比较轻量级的测试工具。 |
|
系统:自己开发的接口管理系统
系统代码:https://github.com/yangjing1989/API
两个关键点:模拟大量并发用户&监控系统负载参数分析系统瓶颈
使用工具:top(h帮助)、sysstat(需要在服务器上安装),uwsgitop,jmeter
*测试环境为了便于测试,修改sysstat获取系统信息的时间间隔为1分钟(默认为10分钟)
vi /etc/cron.d/sysstat

一、录制和回放
1、添加http请求默认值

2、添加录制控制器

3、工作台添加HTTP代理

4、点击【启动】开始录制

5、浏览器设置代理

6、访问被测应用,点击【停止】结束录制
7、删除多余请求

8、在登录请求后添加cookie,cookie值设置参考浏览器中cookie值

9、回放查看结果

二、脚本参数化
1、添加CSV Data Set Config
2、配置参数化数据,并设置参数名称

3、在各请求中应用参数值,如

三、判断页面是否正确
1、添加响应断言

四、模拟多用户并发
1、线程组中设置多用户

2、top查看应用服务器性能,发现CPU、内存等各指标都处于正常范围内。且jmeter中没有输出错误。
3、加大并发用户至200,查看服务器性能,CPU长期高于90%,jmeter中各请求的平均响应时间已经超过5秒,说明系统已经到了极限了。
4、加大并发用户至205,jmeter已经开始出现大量错误。
5、整个过程中发现uwsgi占用大量CPU,uwsgi是我应用使用的web服务器。说明应用程序本身消耗CPU很大,其中jmeter中可看到登录接口响应时间比其他接口都长,每秒从服务器接收的数据量也是其他接口的5倍以上。说明登录接口有待优化。
---------------------
|