Jmeter压力测试

Jmeter压力测试


1.     Jmeter 简介
http://www.cnblogs.com/bravemi/p/5555566.html
一个非常优秀的开源的性能测试工具。
  优点:你用着用着就会发现它的重多优点,当然不足点也会呈现出来。
从性能工具的原理划分:
Jmeter工具和其他性能工具在原理上完全一致,工具包含4个部分:
  (1)负载发生器:用于产生负载,通常以多线程或是多进程的方式模拟用户行为。
  (2)用户运行器:通常是一个脚本运行引擎,用户运行器附加在线程或进程上,根据脚本要求模拟指定的用户行为。
  (3)资源生成器:用于生成测试过程中服务器、负载机的资源数据。
  (4)报表生成器:根据测试中霍地的数据生成报表,提供可视化的数据显示方式。
2.     安装jmeter
jmeter 是Java程序,在Linux windows Mac系统都可以安装,配置好JDK环境就好
https://jmeter.apache.org/download_jmeter.cgi


双击启动


支持中文,不需要汉化。选项中直接选择中文简体。

 



3.     测试步骤


1. 写脚本 或者录制脚本
2. 使用用户自定义参数
3. 场景设计
4. 使用控制器,来控制 模拟多少用户。
5. 使用监听器, 查看测试结果



3.1.     测试脚本

  1 <?xml version="1.0" encoding="UTF-8"?>
  2 <jmeterTestPlan version="1.2" properties="4.0" jmeter="4.0 r1823414">
  3   <hashTree>
  4     <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="测试计划" enabled="true">
  5       <stringProp name="TestPlan.comments"></stringProp>
  6       <boolProp name="TestPlan.functional_mode">false</boolProp>
  7       <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
  8       <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
  9         <collectionProp name="Arguments.arguments"/>
 10       </elementProp>
 11       <stringProp name="TestPlan.user_define_classpath"></stringProp>
 12     </TestPlan>
 13     <hashTree>
 14       <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="线程组" enabled="true">
 15         <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
 16         <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="循环控制器" enabled="true">
 17           <boolProp name="LoopController.continue_forever">false</boolProp>
 18           <stringProp name="LoopController.loops">10</stringProp>
 19         </elementProp>
 20         <stringProp name="ThreadGroup.num_threads">100</stringProp>
 21         <stringProp name="ThreadGroup.ramp_time">10</stringProp>
 22         <longProp name="ThreadGroup.start_time">1509075599000</longProp>
 23         <longProp name="ThreadGroup.end_time">1509075599000</longProp>
 24         <boolProp name="ThreadGroup.scheduler">false</boolProp>
 25         <stringProp name="ThreadGroup.duration"></stringProp>
 26         <stringProp name="ThreadGroup.delay"></stringProp>
 27       </ThreadGroup>
 28       <hashTree>
 29         <HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="HTTP请求" enabled="true">
 30           <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
 31             <collectionProp name="Arguments.arguments"/>
 32           </elementProp>
 33           <stringProp name="HTTPSampler.domain">api.erp.zhaonongzi.com</stringProp>
 34           <stringProp name="HTTPSampler.port"></stringProp>
 35           <stringProp name="HTTPSampler.protocol">http</stringProp>
 36           <stringProp name="HTTPSampler.contentEncoding">utf-8</stringProp>
 37           <stringProp name="HTTPSampler.path">http://api.erp.zhaonongzi.com/APICenter/login.wn?loginForm=%7B%22device_code%22%3A%22863952037843214%22%2C%22mobile%22%3A%2215991608593%22%2C%22password%22%3A%2204dcf2e8981bf2ba0f35fb8ea4a18396%22%2C%22rs%22%3A1524037195%7D</stringProp>
 38           <stringProp name="HTTPSampler.method">POST</stringProp>
 39           <boolProp name="HTTPSampler.follow_redirects">false</boolProp>
 40           <boolProp name="HTTPSampler.auto_redirects">true</boolProp>
 41           <boolProp name="HTTPSampler.use_keepalive">false</boolProp>
 42           <boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
 43           <stringProp name="HTTPSampler.embedded_url_re"></stringProp>
 44           <stringProp name="HTTPSampler.connect_timeout"></stringProp>
 45           <stringProp name="HTTPSampler.response_timeout"></stringProp>
 46         </HTTPSamplerProxy>
 47         <hashTree>
 48           <ResultCollector guiclass="AssertionVisualizer" testclass="ResultCollector" testname="断言结果" enabled="true">
 49             <boolProp name="ResultCollector.error_logging">false</boolProp>
 50             <objProp>
 51               <name>saveConfig</name>
 52               <value class="SampleSaveConfiguration">
 53                 <time>true</time>
 54                 <latency>true</latency>
 55                 <timestamp>true</timestamp>
 56                 <success>true</success>
 57                 <label>true</label>
 58                 <code>true</code>
 59                 <message>true</message>
 60                 <threadName>true</threadName>
 61                 <dataType>true</dataType>
 62                 <encoding>false</encoding>
 63                 <assertions>true</assertions>
 64                 <subresults>true</subresults>
 65                 <responseData>false</responseData>
 66                 <samplerData>false</samplerData>
 67                 <xml>false</xml>
 68                 <fieldNames>true</fieldNames>
 69                 <responseHeaders>false</responseHeaders>
 70                 <requestHeaders>false</requestHeaders>
 71                 <responseDataOnError>false</responseDataOnError>
 72                 <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
 73                 <assertionsResultsToSave>0</assertionsResultsToSave>
 74                 <bytes>true</bytes>
 75                 <sentBytes>true</sentBytes>
 76                 <threadCounts>true</threadCounts>
 77                 <idleTime>true</idleTime>
 78                 <connectTime>true</connectTime>
 79               </value>
 80             </objProp>
 81             <stringProp name="filename"></stringProp>
 82           </ResultCollector>
 83           <hashTree/>
 84           <Summariser guiclass="SummariserGui" testclass="Summariser" testname="生成概要结果" enabled="true"/>
 85           <hashTree/>
 86         </hashTree>
 87         <Arguments guiclass="ArgumentsPanel" testclass="Arguments" testname="用户定义的变量" enabled="true">
 88           <collectionProp name="Arguments.arguments">
 89             <elementProp name="wd" elementType="Argument">
 90               <stringProp name="Argument.name">wd</stringProp>
 91               <stringProp name="Argument.value">jmeter性能测试</stringProp>
 92               <stringProp name="Argument.desc">搜索词</stringProp>
 93               <stringProp name="Argument.metadata">=</stringProp>
 94             </elementProp>
 95           </collectionProp>
 96         </Arguments>
 97         <hashTree/>
 98         <ResultCollector guiclass="StatVisualizer" testclass="ResultCollector" testname="聚合报告" enabled="true">
 99           <boolProp name="ResultCollector.error_logging">false</boolProp>
100           <objProp>
101             <name>saveConfig</name>
102             <value class="SampleSaveConfiguration">
103               <time>true</time>
104               <latency>true</latency>
105               <timestamp>true</timestamp>
106               <success>true</success>
107               <label>true</label>
108               <code>true</code>
109               <message>true</message>
110               <threadName>true</threadName>
111               <dataType>true</dataType>
112               <encoding>true</encoding>
113               <assertions>true</assertions>
114               <subresults>true</subresults>
115               <responseData>true</responseData>
116               <samplerData>true</samplerData>
117               <xml>true</xml>
118               <fieldNames>true</fieldNames>
119               <responseHeaders>true</responseHeaders>
120               <requestHeaders>true</requestHeaders>
121               <responseDataOnError>false</responseDataOnError>
122               <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
123               <assertionsResultsToSave>0</assertionsResultsToSave>
124               <bytes>true</bytes>
125               <sentBytes>true</sentBytes>
126               <url>true</url>
127               <fileName>true</fileName>
128               <hostname>true</hostname>
129               <threadCounts>true</threadCounts>
130               <sampleCount>true</sampleCount>
131               <idleTime>true</idleTime>
132               <connectTime>true</connectTime>
133             </value>
134           </objProp>
135           <stringProp name="filename">/Users/admin/Desktop/aggregate.csv</stringProp>
136         </ResultCollector>
137         <hashTree/>
138         <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="察看结果树" enabled="true">
139           <boolProp name="ResultCollector.error_logging">false</boolProp>
140           <objProp>
141             <name>saveConfig</name>
142             <value class="SampleSaveConfiguration">
143               <time>true</time>
144               <latency>true</latency>
145               <timestamp>true</timestamp>
146               <success>true</success>
147               <label>true</label>
148               <code>true</code>
149               <message>true</message>
150               <threadName>true</threadName>
151               <dataType>true</dataType>
152               <encoding>false</encoding>
153               <assertions>true</assertions>
154               <subresults>true</subresults>
155               <responseData>false</responseData>
156               <samplerData>false</samplerData>
157               <xml>false</xml>
158               <fieldNames>true</fieldNames>
159               <responseHeaders>false</responseHeaders>
160               <requestHeaders>false</requestHeaders>
161               <responseDataOnError>false</responseDataOnError>
162               <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
163               <assertionsResultsToSave>0</assertionsResultsToSave>
164               <bytes>true</bytes>
165               <sentBytes>true</sentBytes>
166               <threadCounts>true</threadCounts>
167               <idleTime>true</idleTime>
168               <connectTime>true</connectTime>
169             </value>
170           </objProp>
171           <stringProp name="filename"></stringProp>
172         </ResultCollector>
173         <hashTree/>
174         <ResultCollector guiclass="GraphVisualizer" testclass="ResultCollector" testname="图形结果" enabled="true">
175           <boolProp name="ResultCollector.error_logging">false</boolProp>
176           <objProp>
177             <name>saveConfig</name>
178             <value class="SampleSaveConfiguration">
179               <time>true</time>
180               <latency>true</latency>
181               <timestamp>true</timestamp>
182               <success>true</success>
183               <label>true</label>
184               <code>true</code>
185               <message>true</message>
186               <threadName>true</threadName>
187               <dataType>true</dataType>
188               <encoding>false</encoding>
189               <assertions>true</assertions>
190               <subresults>true</subresults>
191               <responseData>false</responseData>
192               <samplerData>false</samplerData>
193               <xml>false</xml>
194               <fieldNames>true</fieldNames>
195               <responseHeaders>false</responseHeaders>
196               <requestHeaders>false</requestHeaders>
197               <responseDataOnError>false</responseDataOnError>
198               <saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
199               <assertionsResultsToSave>0</assertionsResultsToSave>
200               <bytes>true</bytes>
201               <sentBytes>true</sentBytes>
202               <threadCounts>true</threadCounts>
203               <idleTime>true</idleTime>
204               <connectTime>true</connectTime>
205             </value>
206           </objProp>
207           <stringProp name="filename"></stringProp>
208         </ResultCollector>
209         <hashTree/>
210       </hashTree>
211     </hashTree>
212   </hashTree>
213 </jmeterTestPlan>



3.2.     配置

接口:
http://api.erp.zhaonongzi.com/APICenter/login.wn?loginForm=%7B%22device_code%22%3A%22863952037843214%22%2C%22mobile%22%3A%2215991608593%22%2C%22password%22%3A%2204dcf2e8981bf2ba0f35fb8ea4a18396%22%2C%22rs%22%3A1524037195%7D




3.3.     查看结果


3.4.    参数和结果说明
https://blog.csdn.net/sunwangdian/article/details/50738870
Number of Threads(users):     一个用户占一个线程,  200个线程就是模拟200个用户
Ramp-Up Period(in seconds):   设置线程需要多长时间全部启动。如果线程数为200 ,准备时长为10 ,那么需要1秒钟启动20个线程。也就是每秒钟启动20个线程。
Loop Count: 每个线程发送请求的次数。如果线程数为200 ,循环次数为10 ,那么每个线程发送10次请求。总请求数为200*10=2000 。如果勾选了“永远”,那么所有线程会一直发送请求,直到选择停止运行脚本。

Ramp-up Period(in seconds)
【1】决定多长时间启动所有线程。如果使用10个线程,ramp-up period是100秒,那么JMeter用100秒使所有10个线程启动并运行。每个线程会在上一个线程启动后10秒(100/10)启动。Ramp-up需要要充足长以避免在启动测试时有一个太大的工作负载,并且要充足小以至于最后一个线程在第一个完成前启动。  一般设置ramp-up=线程数启动,并上下调整到所需的。
【2】用于告知JMeter 要在多长时间内建立全部的线程。默认值是0。如果未指定ramp-up period ,也就是说ramp-up period 为零, JMeter 将立即建立所有线程。假设ramp-up period 设置成T 秒, 全部线程数设置成N个, JMeter 将每隔T/N秒建立一个线程。
【3】Ramp-Up Period(in-seconds)代表隔多长时间执行,0代表同时并发
http://www.51testing.com/html/28/116228-238479.html
https://blog.csdn.net/chwshuang/article/details/48830273
https://blog.csdn.net/xiaojianpitt/article/details/4821554
Samples:表示你这次测试中一共发出了多少个请求,如果模拟10个用户,每个用户迭代10次,那么这里显示100
Average:平均响应时间——默认情况下是单个 Request 的平均响应时间,当使用了 Transaction Controller 时,也可以以Transaction 为单位显示平均响应时间
Median:中位数,也就是 50% 用户的响应时间
90% Line:90% 用户的响应时间
Note:关于 50% 和 90% 并发用户数的含义,请参考下文
http://www.cnblogs.com/jackei/archive/2006/11/11/557972.html
Min:最小响应时间
Max:最大响应时间
Error%:本次测试中出现错误的请求的数量/请求的总数
Throughput:吞吐量——默认情况下表示每秒完成的请求数(Request per Second),当使用了 Transaction Controller 时,也可以表示类似 LoadRunner 的 Transaction per Second 数
KB/Sec:每秒从服务器端接收到的数据量,相当于LoadRunner中的Throughput/Sec


4.     压力测试样例
http://api.erp.zhaonongzi.com/APICenter/login.wn?loginForm={%22device_code%22%3A%22863952037843214%22%2C%22mobile%22%3A%2215991608593%22%2C%22password%22%3A%2204dcf2e8981bf2ba0f35fb8ea4a18396%22%2C%22rs%22%3A1524037195}

100 10 10
server CPU 170%
DB cpu 40%


100 10 50
server CPU 170%
DB cpu 40%

150 10 10
server CPU 170%
DB cpu 40%

200 10 10
server CPU 200%
DB cpu 40%


500 10 10
server CPU 200%
DB cpu 40%

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>Oops, you&#39;ve found a dead link. - JIRA</title><script type="text/javascript">contextPath = "";</script><link type='text/css' rel='stylesheet' href='/static-assets/metal-all.css' media='all'><script src='/static-assets/metal-all.js'></script><!--[if lt IE 9]><link type='text/css' rel='stylesheet' href='/static-assets/metal-all-ie.css' media='all'><script src='/static-assets/metal-all-ie.js'></script><![endif]--><!--[if IE 9]><link type='text/css' rel='stylesheet' href='/static-assets/metal-all-ie9.css' media='all'><![endif]--><meta name="decorator" content="none" /></head><body class=" error-page error404"><script type="text/javascript">document.body.className += " js-enabled";</script><div id="page"><header id="header" role="banner"></header><!-- #header --><section id="content" role="main"><div class="aui-page-panel"><div class="aui-page-panel-inner"><section class="aui-page-panel-content lowerContent"><div id="error-state"><span class="error-type"></span><h1>Oops, you&#39;ve found a dead link.</h1><ul><li>返回 <a href="javascript:window.history.back()">上一页</a></li><li>跳转到 <a href="/secure/MyJiraHome.jspa">主页</a></li></ul></div></section><!-- .aui-page-panel-content --></div><!-- .aui-page-panel-inner --></div><!-- .aui-page-panel --></section><!-- #content --><footer id="footer" role="contentinfo"><section class="footer-body">

5.    参数接口测试
我所测试的就是带参数的接口,只不过拼接到URL中了
下面这个是更好
https://www.cnblogs.com/yangcube/p/7824818.html



wx 2018-04

314144952@qq.com

 

posted on 2018-04-19 17:12  光阴8023  阅读(574)  评论(0编辑  收藏  举报