Jmeter設(shè)計(jì)并發(fā)事件,這應(yīng)該是一項(xiàng)必備技能拦英。
首先來看并發(fā)的概念蜒什。
通常在性能測試中會涉及到并發(fā)用戶數(shù)的概念,有關(guān)并發(fā)用戶數(shù)(系統(tǒng)用戶數(shù))的詳解后續(xù)再記疤估。
(有關(guān)并發(fā)灾常、并行的概念參考https://blog.csdn.net/qq_33290787/article/details/51790605)
并發(fā):本質(zhì)為一個CPU(或多個CPU)在若干道程序(或線程)之間的多路復(fù)用。
參考知乎大神的講法:并發(fā)指的是該系統(tǒng)有處理多事務(wù)的能力铃拇,不一定是同時钞瀑。
啃了啃蟲師的一篇博客http://www.cnblogs.com/fnng/archive/2012/06/25/2562943.html--并發(fā)用戶。
文中對并發(fā)用戶做了很詳細(xì)的解釋慷荔。其中更是對“真正意義上的并發(fā)不存在”一理論進(jìn)行了很詳細(xì)的闡述雕什。推薦認(rèn)真一閱。
那么在Jmeter中是如何進(jìn)行模擬高仿并發(fā)的呢?
有人說了监徘,用集合點(diǎn)晋修,對,集合點(diǎn)確實(shí)達(dá)到并發(fā)目的的一個點(diǎn)凰盔。
還有人說了墓卦,不用集合點(diǎn)也可以,其實(shí)户敬,對后者的觀點(diǎn)落剪,本人認(rèn)為也是正確的,只是在某種意義上尿庐,設(shè)計(jì)該種場景的話要考慮的因素比較多忠怖。
廢話不多說,先一一來上操作抄瑟。
線程組加入線程數(shù)2凡泣,斜坡時間1s,循環(huán)一次皮假。
1s啟動2個線程鞋拟。(2個線程并發(fā))
這是一種原始的Jmeter的設(shè)計(jì)方法。
那么再看一下集合點(diǎn)的設(shè)計(jì)方法惹资。
定時器-->Synchronizing Timer原件贺纲。
看到Synchronizing這個單詞是不是有點(diǎn)熟悉。譯為同步化褪测。
java中使用synchronized為鎖的關(guān)鍵字猴誊。那么再看看其幫助文檔。
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
AttributeDescriptionRequired
NameDescriptive name for this timer that is shown in the tree.No
Number of Simultaneous Users to Group byNumber 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 millisecondsIf 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?0No
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個線程被阻塞懈叹,然后它們都被立即釋放。因此萝毛,同步計(jì)時器可以在測試計(jì)劃的各個點(diǎn)創(chuàng)建大的即時負(fù)載项阴。(百度翻譯)
其目的為阻塞線程滑黔,什么意思呢笆包?就好似過橋一樣,先在橋頭將人擋住略荡,直到人數(shù)阻塞到一定數(shù)量庵佣,釋放障礙物,讓人一起從橋上通過(速度恒定)
該元件只有兩個指標(biāo):Number of Simultaneous Users to Group by:每次釋放的線程數(shù)
Timeout in milliseconds:超時時間汛兜,超時時間后達(dá)不到設(shè)置的線程數(shù)時巴粪,會丟棄繼續(xù)請求
逐一翻譯一下下方的兩段注意語:
#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.
如果以毫秒為單位的超時設(shè)置為0,并且線程的數(shù)量永遠(yuǎn)達(dá)不到“同時分組的用戶數(shù)”,那么測試將無限地暫停肛根。只有強(qiáng)制停止才能阻止它辫塌。在這種情況下,以毫秒為單位設(shè)置超時是一個考慮的選項(xiàng)派哲。
#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內(nèi)同步計(jì)時器塊臼氨,因此如果使用分布式測試確保從未將“同時用戶數(shù)”分組為一個值,其值僅考慮其包含1個噴射器的線程組的用戶數(shù)芭届。
看看效果:
設(shè)置Synchronizing Timer
sampler都是以50储矩、50的進(jìn)行請求。
二褂乍、限制QPS
內(nèi)容來自<軟件性能測試案例剖析-第二版-段念>
書中提到了限制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
AttributeDescriptionRequired
NameDescriptive name for this timer that is shown in the tree.No
Target ThroughputThroughput we want the timer to try to generate.Yes
Calculate Throughput based onthis 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界面有兩個選項(xiàng):
1、期望吞吐量
2逃片、以xx為基礎(chǔ)控制吞吐量
下拉框選擇項(xiàng):
This thread only :分別控制每個線程的吞吐量屡拨,選擇這種模式時,總的吞吐量為設(shè)置的 target Throughput 乘以線程的數(shù)量褥实。
如果我們這里選擇此種模式洁仗,然后設(shè)定了是10個線程,那么我們前面的Target throughput就應(yīng)該填寫1200/10=120 或 20/10*60=120了性锭;
All active threads : 設(shè)置的target Throughput 將分配在每個活躍線程上赠潦,每個活躍線程在上一次運(yùn)行結(jié)束后等待合理的時間后再次運(yùn)行〔莞裕活躍線程指同一時刻同時運(yùn)行的線程她奥。
如果我們這里選擇此種模式,然后設(shè)定了是10個線程怎棱,那么我們前面的Target throughput就應(yīng)該填寫1200/10=120 或 20/10*60=120了哩俭;
All active threads in current thread group :設(shè)置的target Throughput將分配在當(dāng)前線程組的每一個活躍線程上,當(dāng)測試計(jì)劃中只有一個線程組時拳恋,該選項(xiàng)和All active threads選項(xiàng)的效果完全相同凡资。
All active threads (shared ):與All active threads 的選項(xiàng)基本相同,唯一的區(qū)別是谬运,每個活躍線程都會在所有活躍線程上一次運(yùn)行結(jié)束后等待合理的時間后再次運(yùn)行隙赁。
All cative threads in current thread group (shared ):與All active threads in current thread group 基本相同,唯一的區(qū)別是梆暖,每個活躍線程都會在所有活躍線程的上一次運(yùn)行結(jié)束后等待合理的時間后再次運(yùn)行伞访。
OK,再加入書中的例子:限制20QPS的情況下轰驳,查看其響應(yīng)時間等信息厚掷。
加入網(wǎng)上些許分析:(http://ydhome.blog.51cto.com/8948432/1869970)
1弟灼、這里的20 QPS應(yīng)該是指Jmeter發(fā)送請求的QPS,而不是服務(wù)器處理的QPS冒黑;--因?yàn)榧偃缥覀円?0 QPS的速度向服務(wù)器發(fā)送請求田绑,但是服務(wù)器每秒最多只能處理8個請求,那么我們無論如何都無法測得服務(wù)器在20 QPS的情況下的性能數(shù)據(jù)抡爹;
2辛馆、難點(diǎn)在于讓Jmeter【穩(wěn)定地】以20 QPS的速度向服務(wù)器發(fā)送請求;
使用組件Constant Throughput Timer豁延。
因?yàn)閱挝粸閙inute(分鐘)昙篙,因此,需要20*60=1200诱咏。
加入listener苔可,進(jìn)行查看響應(yīng)時間等信息。
歡迎任何形式的轉(zhuǎn)載袋狞,但請務(wù)必注明出處焚辅。 限于本人水平,如果文章和代碼有表述不當(dāng)之處苟鸯,還請不吝賜教同蜻。 ---紫陌花間客