JMeter入门

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ZWE7616175/article/details/82384150

JMeter是开源软件Apache基金协会下的一个性能测试工具,用来部署在服务器端的应用程序的性能。近来,JMeter也被社区作为借口测试工具。我们下载好JMeter软件后,没有安装好工具的小伙伴可以自行下载,和我一起步入JMeter之旅吧。

1.添加虚拟用户组

添加虚拟用户组,如图所示。右击:“TestPlan->Add->Threads(Users)->TreadsGroup.线程组是指一组虚拟用户,这些虚拟用户用来访问被测系统。
这里写图片描述
新建线程组后会出现以下界面。
这里写图片描述
介绍以下线程组中常用的设置。
(1)Number of Threads(users):线程数,指的是模拟用户数,默认为 1,表明一个虚拟用户访问被测系统,如果想要模拟1000个用户,则此处输入1000。
(2)Ramp-Up Period(in seconds):虚拟用户增长时长,估计频率最高的时间长度,以秒为单位,300指的是(300/60=5)5分钟内用户登录完毕。
(3)Loop Count:循环次数,设置一个虚拟用户做实验的次数,默认 1,表示一个虚拟用户做完一遍就停止运行。如果选Forever,那么运行后就不能停下来,除非强制停下来。

2.添加被测页面

在线程组上右击Add->Sampler->HTTP Request,如下图所示。
这里写图片描述
设置名称和IP地址。 剩下的属性可以按照被测系统的属性按需配置,现在都可以为空。
这里写图片描述

然后保存脚本,点击运行测试。想要查看运行情况,可以在选项中的Log Viewer查看运行日志。
这里写图片描述

但是这样的日志文件我们好像也看不出是否跑正确了,给大家另教一招,可以设置监听器让用户更直观的观察测试结果。

3.添加结果监听器

运行测试完毕后,右击 线程组->监听器->察看结果树来查看性能测试中请求和响应的信息,添加完毕后,保存测试脚本,再次运行。
这里写图片描述
运行测试完毕后,点击 查看结果树->百度,可以看到一些信息,比如发送请求的信息和响应数据等。
这里写图片描述

取样器结果:

Thread Name: 线程组 1-1
Sample Start: 2018-09-04 15:06:48 CST
Load time: 311
Connect Time: 251
Latency: 311
Size in bytes: 2781
Sent bytes:114
Headers size in bytes: 400
Body size in bytes: 2381
Sample Count: 1
Error Count: 0
Data type ("text"|"bin"|""): text
Response code: 200
Response message: OK

Response headers:
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 2381
Content-Type: text/html
Date: Tue, 04 Sep 2018 07:06:48 GMT
Etag: "588604f8-94d"
Last-Modified: Mon, 23 Jan 2017 13:28:24 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/


HTTPSampleResult fields:
ContentType: text/html
DataEncoding: null


请求:

GET http://www.baidu.com/

GET data:


[no cookies]

Request Headers:
Connection: keep-alive
Host: www.baidu.com
User-Agent: Apache-HttpClient/4.5.5 (Java/10.0.2)

响应数据:

<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>ç™¾åº¦ä¸€ä¸‹ï¼Œä½ å°±çŸ¥é“</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>æ–°é—»</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&amp;tpl=mn&amp;u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbsp;京ICP证030173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

注意一点,不要将访问百度的线程数设置大,百如果同时访问过多,百度会将你封了的。我们以后同样也可以用JMeter测试自己写的http服务器。

猜你喜欢

转载自blog.csdn.net/ZWE7616175/article/details/82384150