且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-09-12 13:49:52

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这个好用的工具来模拟高并发请求。


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

Download JMeter from its official website:

http://jmeter.apache.org/


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,基于其再创建一个线程组:

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

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

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

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

当然,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对某个OData服务进行高并发性能测试

为了检验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


如何使用jMeter对某个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:

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

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

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

希望这篇文章介绍的jMeter使用技巧对大家工作有所帮助。