Jmeter提供了一個非常有用的定時器,稱為Constant Throughput Timer (常數吞吐量定時器),該定時器可以方便地控制給定的取樣器發送請求的吞吐量。
右鍵點擊fnng.cnblogs.com ,彈出菜單(添加--->定時器--->Constant Throughput Timer)選擇Constant Throughput Timer
Constant Throughput Timer 的主要屬性介紹:
名稱:定時器的名稱
Target throughput(in samples per minute):目標吞吐量。注意這里是每分鍾發送的請求數,因此,對應測試需求中所要求的20 QPS ,這里的值應該是1200 。
Calculate Throughput based on:有5個選項,分別是:
This thread only:控制每個線程的吞吐量,選擇這種模式時,總的吞吐量為設置的 target Throughput 乘以矣線程的數量。
All active threads:設置的target Throughput 將分配在每個活躍線程上,每個活躍線程在上一次運行結束后等待合理的時間后再次運行。活躍線程指同一時刻同時運行的線程。
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 基本相同,唯一的區別是,每個活躍線程都會在所有活躍線程的上一次運行結束后等待合理的時間后再次運行。
如上圖,該元件僅作用於fnng.cnblogs.com ,設置定時器的Target throughput為1200/分鍾(20 QPS),設置Calculate Throughput based on 的值為All active threads 。
當然,Constant Throughput Timer只有在線程組中的線程產生足夠多的request 的情況下才有意義,因此,即使設置了Constant Throughput Timer的值,也可能由於線程組中的線程數量不夠,或是定時器設置不合理等原因導致總體的QPS不能達到預期目標。