溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

發(fā)布時(shí)間:2021-11-30 17:25:21 來(lái)源:億速云 閱讀:182 作者:小新 欄目:編程語(yǔ)言

這篇文章主要介紹了怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試,具有一定借鑒價(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ì)開(kāi)發(fā)了一個(gè)OData服務(wù),現(xiàn)在我接到任務(wù),要測(cè)試這個(gè)服務(wù)在高并發(fā)訪(fǎng)問(wèn)場(chǎng)景下的性能指標(biāo),比如5萬(wàn)個(gè)請(qǐng)求同時(shí)到來(lái)后,每個(gè)請(qǐng)求的平均響應(yīng)時(shí)間,因此我選擇了jMeter這個(gè)好用的工具來(lái)模擬高并發(fā)請(qǐng)求。

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

  1. 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

  1. 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)建一個(gè)新的測(cè)試plan,基于其再創(chuàng)建一個(gè)線(xiàn)程組:


    怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

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)建三個(gè)并發(fā)請(qǐng)求,每個(gè)請(qǐng)求通過(guò)一個(gè)線(xiàn)程實(shí)現(xiàn),每個(gè)線(xiàn)程僅僅執(zhí)行一次。每個(gè)線(xiàn)程派生后的延時(shí)是0秒,意思是主線(xiàn)程同時(shí)創(chuàng)建三個(gè)線(xiàn)程。

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

創(chuàng)建一個(gè)新的HTTP請(qǐng)求,維護(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ù)的相對(duì)路徑了
(5) Use KeepAlive: do NOT select this checkbox - 記得這個(gè)勾別打上

In Parameter tab, maintain query option $search with value ‘Wang’

這個(gè)意思就是每個(gè)并發(fā)請(qǐng)求同時(shí)發(fā)起OData查詢(xún),參數(shù)為我的名字Wang

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

Switch to Advanced tab, choose “HttpClient4” from drop down list for Implementation, and maintain proxy server name and port number.

如果有代理的話(huà),在下圖位置維護(hù)代理服務(wù)器信息。

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

  1. Create a new HTTP Header Manager and specify the basic authentication header field and value.

在HTTP Header Manager里維護(hù)訪(fǎng)問(wèn)這個(gè)Odata服務(wù)的credential。因?yàn)槲覀冮_(kāi)發(fā)的OData服務(wù)支持Basic Authentication這種認(rèn)真方式,所以我在此處的HTTP header字段里維護(hù)Authentication信息。

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

  1. 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)然是顯示測(cè)試結(jié)果了。我使用的是jMeter自帶的Listener,Table類(lèi)型的,以表格形式顯示高并發(fā)請(qǐng)求和響應(yīng)的各項(xiàng)指標(biāo)。

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

Once done, start the test:

一切就緒,點(diǎn)擊這個(gè)綠色的三角形開(kāi)始測(cè)試:

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

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:

測(cè)試完畢后,雙擊我們之前創(chuàng)建的Table Result Listener,我這三個(gè)并發(fā)請(qǐng)求的性能指標(biāo)就顯示出來(lái)了??梢钥吹饺齻€(gè)請(qǐng)求中,最快的請(qǐng)求用了5.1秒,最慢的6.9秒

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

當(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

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

為了檢驗(yàn)jMeter采集的數(shù)據(jù)是否正確可靠,我還花時(shí)間寫(xiě)了一個(gè)Java程序,用JDK自帶的線(xiàn)程池產(chǎn)生并發(fā)請(qǐng)求,測(cè)試的結(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/JavaTwoPlusTwoEquals5/tree/master/src/odata

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

How to generate random query for each thread in JMeter

到目前為止,我的三個(gè)并發(fā)請(qǐng)求進(jìn)行搜索的參數(shù)都是硬編碼的Wang,這個(gè)和實(shí)際場(chǎng)景不太符合。有沒(méi)有辦法生成一些隨機(jī)的搜索字符串,這樣更貼近真實(shí)使用場(chǎng)景呢?

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:

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

參數(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ù)

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

and in http request, just specify reference to this variable via ${uuid}:

在http請(qǐng)求里,用固定的前綴JerryTestCustomer_加上隨機(jī)參數(shù),以此來(lái)構(gòu)造隨機(jī)搜索字符串:

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

So that in the end each thread will issue different query to OData service end point.

通過(guò)Table Result listener,能觀(guān)察到這次確實(shí)每個(gè)請(qǐng)求發(fā)起的搜索都使用了不同的字符串了。

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“怎么使用jMeter對(duì)某個(gè)OData服務(wù)進(jìn)行高并發(fā)性能測(cè)試”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI