资讯专栏INFORMATION COLUMN

如何使用jMeter对某个OData服务进行高并发性能测试

qylost / 1547人阅读

摘要:我们公司某团队开发了一个服务,现在我接到任务,要测试这个服务在高并发访问场景下的性能指标,比如万个请求同时到来后,每个请求的平均响应时间,因此我选择了这个好用的工具来模拟高并发请求。创建,主要用途当然是显示测试结果了。

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:

http://jmeter.apache.org/

Go to the installation folder, add the following text in file binuser.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/Ja...

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的原创文章,请关注公众号"汪子熙":

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/72984.html

相关文章

  • SAP OData编程指南

    摘要:目前被广泛用于和的众多应用中,以及和一些正在开发的新一代云产品中。年月时,我和德国一位负责的同事就这个话题在半小时的电话会议里产生了争执。德国同事看了之后,同意了我的意见。和微信集成系列教程这个系列教程里,和微信的交互,使用了,使用了。 OData(Open Data Protocol)协议是一个开放的工业标准,用于定义RESTFul API的设计和使用。我的文章标题前加上SAP的前缀...

    X1nFLY 评论0 收藏0
  • SAP OData编程指南

    摘要:目前被广泛用于和的众多应用中,以及和一些正在开发的新一代云产品中。年月时,我和德国一位负责的同事就这个话题在半小时的电话会议里产生了争执。德国同事看了之后,同意了我的意见。和微信集成系列教程这个系列教程里,和微信的交互,使用了,使用了。 OData(Open Data Protocol)协议是一个开放的工业标准,用于定义RESTFul API的设计和使用。我的文章标题前加上SAP的前缀...

    wanghui 评论0 收藏0
  • 使用jMeter构造大量并发HTTP请求进行服务性能测试

    摘要:比如我开发好了一个微服务,想测试其在大并发请求下的性能表现如何。比较方便的一个做法是使用工具来构造这些请求。这个请求的意思是使用请求查询账号名称为的实例。维护完毕之后点执行按钮,会观察到个线程同时发出请求,并能看到每个请求的响应时间。 比如我开发好了一个微服务,想测试其在大并发请求下的性能表现如何。 比较方便的一个做法是使用工具jMeter来构造这些请求。 创建一个新的工程: show...

    LeanCloud 评论0 收藏0
  • 使用jMeter基于SAP ID service进行Authentication的Restful

    摘要:因为这个项目最后会在年月日于上海举行的云大会上展示,所以当时完成集成工作后心想,还是得提前测试一下咱们的在响应并发请求时的性能做到心里有数。 这篇文章本来Jerry只在SAP社区上写了英文版的,可以通过点击文末的阅读原文获得。后来有两位做Marketing Cloud开发的德国同事,写邮件询问关于文章的更多细节,声称这种方式对他们自己的API性能测试很有用,所以我觉得还是值得用中文再写...

    longmon 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<