摘要:我們公司某團(tuán)隊(duì)開發(fā)了一個服務(wù),現(xiàn)在我接到任務(wù),要測試這個服務(wù)在高并發(fā)訪問場景下的性能指標(biāo),比如萬個請求同時到來后,每個請求的平均響應(yīng)時間,因此我選擇了這個好用的工具來模擬高并發(fā)請求。創(chuàng)建,主要用途當(dāng)然是顯示測試結(jié)果了。
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.
我們公司某團(tuán)隊(duì)開發(fā)了一個OData服務(wù),現(xiàn)在我接到任務(wù),要測試這個服務(wù)在高并發(fā)訪問場景下的性能指標(biāo),比如5萬個請求同時到來后,每個請求的平均響應(yīng)時間,因此我選擇了jMeter這個好用的工具來模擬高并發(fā)請求。
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.
創(chuàng)建一個新的測試plan,基于其再創(chuàng)建一個線程組:
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 )
下列設(shè)置意思是我想創(chuàng)建三個并發(fā)請求,每個請求通過一個線程實(shí)現(xiàn),每個線程僅僅執(zhí)行一次。每個線程派生后的延時是0秒,意思是主線程同時創(chuàng)建三個線程。
創(chuàng)建一個新的HTTP請求,維護(hù)下列設(shè)置:
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服務(wù)的相對路徑了
(5) Use KeepAlive: do NOT select this checkbox - 記得這個勾別打上
In Parameter tab, maintain query option $search with value ‘Wang’
這個意思就是每個并發(fā)請求同時發(fā)起OData查詢,參數(shù)為我的名字Wang
Switch to Advanced tab, choose “HttpClient4” from drop down list for Implementation, and maintain proxy server name and port number.
如果有代理的話,在下圖位置維護(hù)代理服務(wù)器信息。
Create a new HTTP Header Manager and specify the basic authentication header field and value.
在HTTP Header Manager里維護(hù)訪問這個Odata服務(wù)的credential。因?yàn)槲覀冮_發(fā)的OData服務(wù)支持Basic Authentication這種認(rèn)真方式,所以我在此處的HTTP header字段里維護(hù)Authentication信息。
Create a listener for the test plan. In my test I simply choose the most simple one: View Results in Table.
創(chuàng)建listener,主要用途當(dāng)然是顯示測試結(jié)果了。我使用的是jMeter自帶的Listener,Table類型的,以表格形式顯示高并發(fā)請求和響應(yīng)的各項(xiàng)指標(biāo)。
Once done, start the test:
一切就緒,點(diǎn)擊這個綠色的三角形開始測試:
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:
測試完畢后,雙擊我們之前創(chuàng)建的Table Result Listener,我這三個并發(fā)請求的性能指標(biāo)就顯示出來了。可以看到三個請求中,最快的請求用了5.1秒,最慢的6.9秒
當(dāng)然,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
為了檢驗(yàn)jMeter采集的數(shù)據(jù)是否正確可靠,我還花時間寫了一個Java程序,用JDK自帶的線程池產(chǎn)生并發(fā)請求,測試的結(jié)果和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
到目前為止,我的三個并發(fā)請求進(jìn)行搜索的參數(shù)都是硬編碼的Wang,這個和實(shí)際場景不太符合。有沒有辦法生成一些隨機(jī)的搜索字符串,這樣更貼近真實(shí)使用場景呢?
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:
當(dāng)然有辦法:右鍵菜單,Add->Pre Processors(預(yù)處理器)->User Parameters:
參數(shù)名Parameter name,取為uuid
參數(shù)值Parameter value: use JMeter predefined function __Random to generate random number.
使用jMeter自帶的隨機(jī)數(shù)生成函數(shù)__Random。
因此最后參數(shù)uuid的值為${__Random(1,100)},意思是生成1到100內(nèi)的隨機(jī)正整數(shù)
and in http request, just specify reference to this variable via ${uuid}:
在http請求里,用固定的前綴JerryTestCustomer_加上隨機(jī)參數(shù),以此來構(gòu)造隨機(jī)搜索字符串:
So that in the end each thread will issue different query to OData service end point.
通過Table Result listener,能觀察到這次確實(shí)每個請求發(fā)起的搜索都使用了不同的字符串了。
希望這篇文章介紹的jMeter使用技巧對大家工作有所幫助。
要獲取更多Jerry的原創(chuàng)文章,請關(guān)注公眾號"汪子熙":
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://m.hztianpu.com/yun/72984.html
摘要:目前被廣泛用于和的眾多應(yīng)用中,以及和一些正在開發(fā)的新一代云產(chǎn)品中。年月時,我和德國一位負(fù)責(zé)的同事就這個話題在半小時的電話會議里產(chǎn)生了爭執(zhí)。德國同事看了之后,同意了我的意見。和微信集成系列教程這個系列教程里,和微信的交互,使用了,使用了。 OData(Open Data Protocol)協(xié)議是一個開放的工業(yè)標(biāo)準(zhǔn),用于定義RESTFul API的設(shè)計(jì)和使用。我的文章標(biāo)題前加上SAP的前綴...
摘要:目前被廣泛用于和的眾多應(yīng)用中,以及和一些正在開發(fā)的新一代云產(chǎn)品中。年月時,我和德國一位負(fù)責(zé)的同事就這個話題在半小時的電話會議里產(chǎn)生了爭執(zhí)。德國同事看了之后,同意了我的意見。和微信集成系列教程這個系列教程里,和微信的交互,使用了,使用了。 OData(Open Data Protocol)協(xié)議是一個開放的工業(yè)標(biāo)準(zhǔn),用于定義RESTFul API的設(shè)計(jì)和使用。我的文章標(biāo)題前加上SAP的前綴...
摘要:比如我開發(fā)好了一個微服務(wù),想測試其在大并發(fā)請求下的性能表現(xiàn)如何。比較方便的一個做法是使用工具來構(gòu)造這些請求。這個請求的意思是使用請求查詢賬號名稱為的實(shí)例。維護(hù)完畢之后點(diǎn)執(zhí)行按鈕,會觀察到個線程同時發(fā)出請求,并能看到每個請求的響應(yīng)時間。 比如我開發(fā)好了一個微服務(wù),想測試其在大并發(fā)請求下的性能表現(xiàn)如何。 比較方便的一個做法是使用工具jMeter來構(gòu)造這些請求。 創(chuàng)建一個新的工程: show...
摘要:因?yàn)檫@個項(xiàng)目最后會在年月日于上海舉行的云大會上展示,所以當(dāng)時完成集成工作后心想,還是得提前測試一下咱們的在響應(yīng)并發(fā)請求時的性能做到心里有數(shù)。 這篇文章本來Jerry只在SAP社區(qū)上寫了英文版的,可以通過點(diǎn)擊文末的閱讀原文獲得。后來有兩位做Marketing Cloud開發(fā)的德國同事,寫郵件詢問關(guān)于文章的更多細(xì)節(jié),聲稱這種方式對他們自己的API性能測試很有用,所以我覺得還是值得用中文再寫...
閱讀 3187·2021-11-22 13:54
閱讀 896·2021-11-04 16:08
閱讀 5469·2021-10-11 11:09
閱讀 3669·2021-09-22 16:05
閱讀 1076·2019-08-30 15:54
閱讀 449·2019-08-30 15:44
閱讀 671·2019-08-30 14:05
閱讀 1092·2019-08-30 12:46