Jmeter(三十六)縱橫併發、限制QPS

1、縱橫併發

Jmeter設計併發事件,這應該是一項必備技能。html

首先來看併發的概念。java

一般在性能測試中會涉及到併發用戶數的概念,有關併發用戶數(系統用戶數)的詳解後續再記。服務器

(有關併發、並行的概念參考https://blog.csdn.net/qq_33290787/article/details/51790605)併發

併發:本質爲一個CPU(或多個CPU)在若干道程序(或線程)之間的多路複用。分佈式

參考知乎大神的講法:併發指的是該系統有處理多事務的能力,不必定是同時。ide

啃了啃蟲師的一篇博客http://www.cnblogs.com/fnng/archive/2012/06/25/2562943.html--併發用戶。性能

文中對併發用戶作了很詳細的解釋。其中更是對「真正意義上的併發不存在」一理論進行了很詳細的闡述。推薦認真一閱。測試

那麼在Jmeter中是如何進行模擬高仿併發的呢?ui

有人說了,用集合點,對,集合點確實達到併發目的的一個點。this

還有人說了,不用集合點也能夠,其實,對後者的觀點,本人認爲也是正確的,只是在某種意義上,設計該種場景的話要考慮的因素比較多。

廢話很少說,先一一來上操做。

線程組加入線程數2,斜坡時間1s,循環一次。

1s啓動2個線程。(2個線程併發)

這是一種原始的Jmeter的設計方法。

那麼再看一下集合點的設計方法。

定時器-->Synchronizing Timer原件。

看到Synchronizing這個單詞是否是有點熟悉。譯爲同步化。

java中使用synchronized爲鎖的關鍵字。那麼再看看其幫助文檔。

The purpose of the SyncTimer is to block threads until X number of threads have been blocked, and then they are all released at once. A SyncTimer can thus create large instant loads at various points of the test plan.

Control Panel

Parameters

Attribute Description Required
Name Descriptive name for this timer that is shown in the tree. No
Number of Simultaneous Users to Group by Number of threads to release at once. Setting it to 0 is equivalent to setting it to Number of threads in Thread Group. Yes
Timeout in milliseconds If set to 0, Timer will wait for the number of threads to reach the value in "Number of Simultaneous Users to Group". If superior to 0, then timer will wait at max "Timeout in milliseconds" for the number of Threads. If after the timeout interval the number of users waiting is not reached, timer will stop waiting. Defaults to 0 No

 

If timeout in milliseconds is set to 0 and number of threads never reaches "Number of Simultaneous Users to Group by" then Test will pause infinitely. Only a forced stop will stop it. Setting Timeout in milliseconds is an option to consider in this case.

 

Synchronizing timer blocks only within one JVM, so if using Distributed testing ensure you never set "Number of Simultaneous Users to Group by" to a value superior to the number of users of its containing Thread group considering 1 injector only.

The purpose of SycTimeType is to stop threads until X threads are blocked, and they are immediately released. Therefore, synchronous timer can create large immediate load at every point of the test plan.

SycTimeType的目的是阻止線程,直到X個線程被阻塞,而後它們都被當即釋放。所以,同步計時器能夠在測試計劃的各個點建立大的即時負載。(百度翻譯)

其目的爲阻塞線程,什麼意思呢?就好似過橋同樣,先在橋頭將人擋住,直到人數阻塞到必定數量,釋放障礙物,讓人一塊兒從橋上經過(速度恆定)

該元件只有兩個指標:Number of Simultaneous Users to Group by:每次釋放的線程數

          Timeout in milliseconds:超時時間,超時時間後達不到設置的線程數時,會丟棄繼續請求

逐一翻譯一下下方的兩段注意語:

#If timeout in milliseconds is set to 0 and number of threads never reaches "Number of Simultaneous Users to Group by" then Test will pause infinitely. Only a forced stop will stop it. Setting Timeout in milliseconds is an option to consider in this case.

若是以毫秒爲單位的超時設置爲0,而且線程的數量永遠達不到「同時分組的用戶數」,那麼測試將無限地暫停。只有強制中止才能阻止它。在這種狀況下,以毫秒爲單位設置超時是一個考慮的選項。

#Synchronizing timer blocks only within one JVM, so if using Distributed testing ensure you never set "Number of Simultaneous Users to Group by" to a value superior to the number of users of its containing Thread group considering 1 injector only.

 僅在一個JVM內同步計時器塊,所以若是使用分佈式測試確保從未將「同時用戶數」分組爲一個值,其值僅考慮其包含1個噴射器的線程組的用戶數。

看看效果:

設置Synchronizing Timer

sampler都是以50、50的進行請求。

 

2、限制QPS

內容來自<軟件性能測試案例剖析-第二版-段念>

書中提到了限制QPS的步驟。

用到組件:定時器-->Constant Throughput Timer(恆定吞吐量定時器)

This timer introduces variable pauses, calculated to keep the total throughput (in terms of samples per minute) as close as possible to a give figure. Of course the throughput will be lower if the server is not capable of handling it, or if other timers or time-consuming test elements prevent it.

N.B. although the Timer is called the Constant Throughput timer, the throughput value does not need to be constant. It can be defined in terms of a variable or function call, and the value can be changed during a test. The value can be changed in various ways:

  • using a counter variable
  • using a JavaScript or BeanShell function to provide a changing value
  • using the remote BeanShell server to change a JMeter property

See Best Practices for further details.

 

Note that the throughput value should not be changed too often during a test - it will take a while for the new value to take effect.

Control Panel

Parameters

Attribute Description Required
Name Descriptive name for this timer that is shown in the tree. No
Target Throughput Throughput we want the timer to try to generate. Yes
Calculate Throughput based on
  • this thread only - each thread will try to maintain the target throughput. The overall throughput will be proportional to the number of active threads.
  • all active threads in current thread group - the target throughput is divided amongst all the active threads in the group. Each thread will delay as needed, based on when it last ran.
  • all active threads - the target throughput is divided amongst all the active threads in all Thread Groups. Each thread will delay as needed, based on when it last ran. In this case, each other Thread Group will need a Constant Throughput timer with the same settings.
  • all active threads in current thread group (shared) - as above, but each thread is delayed based on when any thread in the group last ran.
  • all active threads (shared) - as above; each thread is delayed based on when any thread last ran.

 GUI界面有兩個選項:

  一、指望吞吐量

  二、以xx爲基礎控制吞吐量

下拉框選擇項:

This thread only :分別控制每一個線程的吞吐量,選擇這種模式時,總的吞吐量爲設置的 target Throughput 乘以線程的數量。

若是咱們這裏選擇此種模式,而後設定了是10個線程,那麼咱們前面的Target throughput就應該填寫1200/10=120 或 20/10*60=120了;

 

All active threads : 設置的target Throughput 將分配在每一個活躍線程上,每一個活躍線程在上一次運行結束後等待合理的時間後再次運行。活躍線程指同一時刻同時運行的線程。

若是咱們這裏選擇此種模式,而後設定了是10個線程,那麼咱們前面的Target throughput就應該填寫1200/10=120 或 20/10*60=120了;

 

All active threads in current thread group :設置的target Throughput將分配在當前線程組的每個活躍線程上,當測試計劃中只有一個線程組時,該選項和All active threads選項的效果徹底相同。

 

All active threads (shared ):與All active threads 的選項基本相同,惟一的區別是,每一個活躍線程都會在全部活躍線程上一次運行結束後等待合理的時間後再次運行。

 

All cative threads in current thread group (shared ):與All active threads in current thread group 基本相同,惟一的區別是,每一個活躍線程都會在全部活躍線程的上一次運行結束後等待合理的時間後再次運行。

 

OK,再加入書中的例子:限制20QPS的狀況下,查看其響應時間等信息。

加入網上些許分析:(http://ydhome.blog.51cto.com/8948432/1869970)

一、這裏的20 QPS應該是指Jmeter發送請求的QPS,而不是服務器處理的QPS;--由於假如咱們以20 QPS的速度向服務器發送請求,可是服務器每秒最多隻能處理8個請求,那麼咱們不管如何都沒法測得服務器在20 QPS的狀況下的性能數據;

二、難點在於讓Jmeter【穩定地】以20 QPS的速度向服務器發送請求;

使用組件Constant Throughput Timer。

由於單位爲minute(分鐘),所以,須要20*60=1200。

加入listener,進行查看響應時間等信息。

相關文章
相關標籤/搜索