For project reason I have to measure the performance of OData service being accessed parallelly. And I plan to use the open source tool JMeter to generate a huge number of request in parallel and measure the average response time. Since I am a beginner for JMeter, I write down what I have learned into this blog. I will continue to explorer the advanced feature of JMeter in my daily work.
我们公司某团队开发了一个OData服务,现在我接到任务,要测试这个服务在高并发访问场景下的性能指标,比如5万个请求同时到来后,每个请求的平均响应时间,因此我选择了jMeter这个好用的工具来模拟高并发请求。
- Download JMeter from its official website:
Go to the installation folder, add the following text in file \bin\user.properties:
httpclient4.retrycount=1
hc.parameters.file=hc.parameters
-
Create a new test plan for example Customer_Query_OData_test, and right click on it and create a thread group from context menu.
创建一个新的测试plan,基于其再创建一个线程组:
Below configuration means I would like to generate three request in parallel via three threads, each thread is executed only once. And there is no delay during the spawn of each threads ( Ramp-Up Period = 0 )
下列设置意思是我想创建三个并发请求,每个请求通过一个线程实现,每个线程仅仅执行一次。每个线程派生后的延时是0秒,意思是主线程同时创建三个线程。
创建一个新的HTTP请求,维护下列设置:
Create a new Http Request and maintain the following settings:
(1) Protocol: https
(2) Server name:
(3) Http request method: GET
(4) Http path: /sap/c4c/odata/v1/c4codata/AccountCollection/ - 这就是OData服务的相对路径了
(5) Use KeepAlive: do NOT select this checkbox - 记得这个勾别打上
In Parameter tab, maintain query option $search with value ‘Wang’
这个意思就是每个并发请求同时发起OData查询,参数为我的名字Wang
Switch to Advanced tab, choose “HttpClient4” from drop down list for Implementation, and maintain proxy server name and port number.
如果有代理的话,在下图位置维护代理服务器信息。
- Create a new HTTP Header Manager and specify the basic authentication header field and value.
在HTTP Header Manager里维护访问这个Odata服务的credential。因为我们开发的OData服务支持Basic Authentication这种认真方式,所以我在此处的HTTP header字段里维护Authentication信息。
- Create a listener for the test plan. In my test I simply choose the most simple one: View Results in Table.
创建listener,主要用途当然是显示测试结果了。我使用的是jMeter自带的Listener,Table类型的,以表格形式显示高并发请求和响应的各项指标。
Once done, start the test:
一切就绪,点击这个绿色的三角形开始测试:
After the test is finished, double click on View Result Listener and the response time for each request and the average response time is displayed there:
测试完毕后,双击我们之前创建的Table Result Listener,我这三个并发请求的性能指标就显示出来了。可以看到三个请求中,最快的请求用了5.1秒,最慢的6.9秒
当然,jMeter也支持命令行方式使用:
Or you can use command line to achieve the same:
-n: use non-GUI mode
-t: specify which test plan you want to run
-l: specify the path of output result file
为了检验jMeter采集的数据是否正确可靠,我还花时间写了一个Java程序,用JDK自带的线程池产生并发请求,测试的结果和jMeter是一致的。
And I have written a simple Java application to generate parallel request via multiple thread and the result measured in Java program is consistent with the one got from JMeter.
The source code could be found from my github:
我的Java程序放在我的github上:
https://github.com/i042416/JavaTwoPlusTwoEquals5/tree/master/src/odata
How to generate random query for each thread in JMeter
到目前为止,我的三个并发请求进行搜索的参数都是硬编码的Wang,这个和实际场景不太符合。有没有办法生成一些随机的搜索字符串,这样更贴近真实使用场景呢?
Suppose we would like each thread in JMeter to generate different customer query via OData with the format JerryTestCustomer_<1~100>, we can simply create a new user parameter:
当然有办法:右键菜单,Add->Pre Processors(预处理器)->User Parameters:
参数名Parameter name,取为uuid
参数值Parameter value: use JMeter predefined function __Random to generate random number.
使用jMeter自带的随机数生成函数__Random。
因此最后参数uuid的值为${__Random(1,100)},意思是生成1到100内的随机正整数
and in http request, just specify reference to this variable via ${uuid}:
在http请求里,用固定的前缀JerryTestCustomer_加上随机参数,以此来构造随机搜索字符串:
So that in the end each thread will issue different query to OData service end point.
通过Table Result listener,能观察到这次确实每个请求发起的搜索都使用了不同的字符串了。
希望这篇文章介绍的jMeter使用技巧对大家工作有所帮助。
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关推荐
使用JMeter进行性能测试
JMeter 之TCP服务器并发压力测试,图文详细介绍,傻瓜式操作。
1.Jmeter对HTTP请求压力测试、并发测试的简单使用方法 2.HTTP请求压力测试、并发测试的简单使用方法 3.Jmeter对HTTP请求压力测试、并发测试的简单使用方法
使用JMeter 对Web服务器压力测试
主要介绍badboy + jmeter并发性能测试,及badboy的使用
jmeter4.0进行微信小程序测试(jmeter性能测试教程) jmeter4.0进行微信小程序测试详细步骤指导书jmeter4.0进行微信小程序测试详细步骤指导书jmeter4.0进行微信小程序测试详细步骤指导书
熟练学习Jmeter工具独立完成常见的性能测试项目熟练使用Jmeter进行脚本开发熟练使用Jmeter进行性能测试熟练使用Jmeter进行接口测试 1) 第一阶段为JMETER 5.4.1 工具使用篇,通过Jmeter 介绍和安装、http 取样器、...
Apache JMeter是Apache组织开发的基于Java的压力测试工具。...JMeter 可以用于对服务器、网络或对象模拟巨大的负载,来在不同压力类别下测试它们的强度和分析整体性能、多应用于c/s架构的测试........
JMeter通常被用来对一些静态的或者动态资源进行性能测试。然后通过分析它产生的性能图表来判断测试结果。简单的说:是Apache下的一个测试工具,可以对服务器进行并发测试,测试服务器所能承受的并发量,以各种曲线图...
Jmeter性能测试报告模板
性能测试工具JMeter书籍(6本)目录知识点(思维导图加图)整理.rar 根据如下6本性能测试、JMeter书籍收集整理重点知识点: 2012年《零成本实现Web性能测试:基于Apache JMeter》 2016年《大型IT系统性能测试入门...
使用JMeter 对SOAP 应用进行压力或性能测试.pdf
1.能够对HTTP和FTP服务器进行压力和性能测试, 也可以对任何数据库进行同样的测试(通过JDBC)。 2.完全的可移植性和100% 纯java。 3.完全 Swing 和轻量组件支持(预编译的JAR使用 javax.swing.*)包。 4.完全多线程 ...
jmeter可以使用第三方的录制工具(badboy)或者使用自身的软件的录制功能进行,jmeter录制原理:是通过代理http服务器抓取用户操作网站过程中的链接。 jmeter可以在设置http代理服务器的时候,过滤掉不需要的css、...
jmeter-压力测试报告-超细,Jmeter性能测试工具使用总结
讲解开源负载工具JMeter的体系结构、脚本开发、负载模拟、测试监听等内容,让读者可以从零开始学会使用一个主流的负载工具,此部分是市面上到目前为止对JMeter讲解较全面的内容,掌握其内容即可以进行性能测试脚本...
本书首先介绍基础的性能测试理论,接着详细介绍如何使用jmeter完成各种类型的性能测试。实战章节中作者以测试某大型保险公司电话销售系统为例,手把手教会读者如何用jmeter来完成一个实际的性能测试任务。 本书...
《零成本实现Web性能测试:基于Apache JMeter》首先介绍基础的性能测试理论,接着详细介绍如何使用JMeter完成各种类型的性能测试。实战章节中作者以测试某大型保险公司电话销售系统为例,手把手教会读者如何用JMeter...