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 \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也支援指令行方式使用:
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/odataHow 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使用技巧對大家工作有所幫助。