[Jmeter(三十) 循环+事务的妙用]
先提一个小问题,也是当时在对Jmeter还是懵懂之时,亲身碰到过的一个问题。
真实的业务场景---“登录一次,提交订单N次”,当然该处是两个接口。
提现接口是需要判断用户是否在线,换句话说,服务器需要验证其是否登录成功。
登录成功之后,返回Cookie,提交订单接口包含该Cookie一起发送至服务器,才会提现成功。
实现思路:
HTTP Cookie管理器
仅一次控制器
登录接口
循环控制器
提现接口
(忽略其中的事务控制器)
该目录结构,实现思想有效解决了前面提到的业务需求。
观察上方的Jmeter的目录结构,支付接口是需要提交订单接口的response报文信息,此处,若是加入循环,那么支付接口是否会有序的获取到提交订单接口的response报文参数信息呢?
答案是不一定的,尤其是做外部参数化文件之时,该问题会更为明显。
循环控制器+事务控制器很有效的解决了该问题。有需要可以加入Think Time
[Jmeter(三十一) 乱码解读]
众所周知,编码的问题影响着众多开发者,当然见多不怪。
先扒了一个编码的原因,也就是为什么要编码:
- 计算机中存储信息的最小单元是一个字节即 8 个 bit,所以能表示的字符范围是 0~255 个
- 人类要表示的符号太多,无法用一个字节来完全表示
- 要解决这个矛盾必须需要一个新的数据结构 char,从 char 到 byte 必须编码
Jmeter中也是存在编码(也就是常见的‘乱码’)问题。
常见的编码格式有ASCII、ISO-8859-1、GB2312、GBK、UTF-8、UTF-16等,而GB2312、GBK、UTF-8、UTF-16格式便是常用的汉字编码格式。
回到正主,Jmeter中的编码又是什么呢?
该段内容截取至${jmeter_home}\bin\jmeter.propeties文件
从截图中的这段注释中便可以看到。jmeter默认是以ISO-8859-1编码格式进行编码的。
那么在GUI界面进行操作的过程中,与某些响应报文的编码格式不一致时,便会出现乱码情况。如下:
响应乱码便是如此。
解决方案:1)修改配置文件中的编码格式(上方截图所示)
2)直接在请求处的编码格式中输入编码格式(下图示)
还有一种乱码便是请求报文乱码,常出现场景:外部文件参数化。
CSV文件中未定义编码格式。
加入编码格式,请求重试
还有一种乱码情况,通常在录制的情况会出现。
具体的场景是,录制完成之后,接口的请求body data中有乱码信息,例如某些json字符串等。
通过翻阅官方文档,是有该情况。
body data中文乱码,是因为jmeter自3.0起,优化了body data后默认的字体(consolas)不支持中文显示;
解决方案:在jmeter.properties中查找jsyntaxtextarea.font.family,取消注释,使用hack字体即可(当然也可以换成支持的其他字符集)
本人也使用3.2进行了录制,部分body data中的json字符串是有这种不支持中文显示的乱码情况,不过,本人也进行调试,是不影响使用的,可以进行请求使用。
[Jmeter(三十二)“自定义函数开发”]
“技术是业务的支撑”,已经不是第一次听到这句话,因为有各种各样的需求,因此衍生了许多各种各样的技术。共勉!
前面有提到提到过Jmeter的安装目录结构,也提到Jmeter的常用函数功能,有部分工作使用函数便可以完成,有满足,那肯定是有不满足的,本篇来记录函数的开发。
先贴内置函数图,该jar包位于${jmeter_home}\lib\ext目录下,ApacheJMeter_functions.jar
有很多熟悉的名字。
那么就挑一个典型的来反编译一下。Random.class。
GUI界面显示内容:
前端实现Random函数,定义个三个参数。
上源码:
1 //
2 // Source code recreated from a .class file by IntelliJ IDEA
3 // (powered by Fernflower decompiler)
4 //
5
6 package org.apache.jmeter.functions;
7
8 import java.util.Collection;
9 import java.util.LinkedList;
10 import java.util.List;
11 import java.util.concurrent.ThreadLocalRandom;
12 import org.apache.jmeter.engine.util.CompoundVariable;
13 import org.apache.jmeter.samplers.SampleResult;
14 import org.apache.jmeter.samplers.Sampler;
15 import org.apache.jmeter.threads.JMeterVariables;
16 import org.apache.jmeter.util.JMeterUtils;
17
18 public class Random extends AbstractFunction {
19 private static final List<String> desc = new LinkedList();
20 private static final String KEY = "__Random";
21 private CompoundVariable varName;
22 private CompoundVariable minimum;
23 private CompoundVariable maximum;
24
25 public Random() {
26 }
27
28 public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException {
29 long min = Long.parseLong(this.minimum.execute().trim());
30 long max = Long.parseLong(this.maximum.execute().trim());
31 long rand = ThreadLocalRandom.current().nextLong(min, max + 1L);
32 String randString = Long.toString(rand);
33 if (this.varName != null) {
34 JMeterVariables vars = this.getVariables();
35 String varTrim = this.varName.execute().trim();
36 if (vars != null && varTrim.length() > 0) {
37 vars.put(varTrim, randString);
38 }
39 }
40
41 return randString;
42 }
43
44 public void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException {
45 this.checkParameterCount(parameters, 2, 3);
46 Object[] values = parameters.toArray();
47 this.minimum = (CompoundVariable)values[0];
48 this.maximum = (CompoundVariable)values[1];
49 if (values.length > 2) {
50 this.varName = (CompoundVariable)values[2];
51 } else {
52 this.varName = null;
53 }
54
55 }
56
57 public String getReferenceKey() {
58 return "__Random";
59 }
60
61 public List<String> getArgumentDesc() {
62 return desc;
63 }
64
65 static {
66 desc.add(JMeterUtils.getResString("minimum_param"));
67 desc.add(JMeterUtils.getResString("maximum_param"));
68 desc.add(JMeterUtils.getResString("function_name_paropt"));
69 }
70 }
观察这段代码、整体结构大致分为三个部分。
定义、实现逻辑、返回定义。
在编写实现函数代码的时候需要注意的几个细节:
1、包名必须是以functions结尾。
2、类继承AbstractFunction。
OK,照猫画虎,编写其中的逻辑:
1 String result = "";
2
3 try {
4 int a = Integer.valueOf(str1).intValue();
5 int b = Integer.valueOf(str2).intValue();
6 int c = Integer.valueOf(str3).intValue();
7 result = String.valueOf(addInt(a, b, c));
8 } catch (Exception e) {
9 // TODO Auto-generated catch block
10 e.printStackTrace();
11 }
12
13 if ((localJMeterVariables != null) && (this.values.length > 0)) {
14 localJMeterVariables.put(str4, result);
15 }
16
17 return result;
18 }
19
20 private int addInt(int a, int b, int c) {
21 // TODO Auto-generated method stub
22 return a + b + c;
23 }
三个正整数相加,返回和。
打包,将jar包放入lib\ext目录下,启动Jmeter
调试一下。
像外行一样去思考,像专家一样去实践。
----金出武雄
[Jmeter(三十三)Stepping Thread Group]
碰巧最近在做性能测试,就记一下Jmeter的第三方插件Stepping Thread Group。
具体一些插件信息,可以去:jmeter-plugins.org去进行下载。
该插件目前是已经被弃用的。不过得益于它良好的一些界面指标,加压方式仍可选择。
横坐标和纵坐标分别是:运行时间和线程数。
本图是“2s启动一个线程”的例子。
就指标来记一记:
在取样器错误后要执行的操作--姑且不计、与传统线程组类似。
This group will start XXX threads --------------该线程组一共启动多少线程数量,上图是一共启动10个线程
First wait for XXX seconds --------------启动第一个线程需要等多久,上图是等待0秒
Then start XXX threads --------------最开始启动几个线程,上图是启动1个线程
next add XXX threads xxx seconds XXX using ramp-up XXX seconds ---------------每隔几秒,在几秒内启动几个线程,上图是每隔2秒,在2秒内启动1个线程
Then hold load for XXX seconds --------------全部线程加载完毕,持续运行多少秒,上图是10个线程全部加载完毕,持续运行10s
Finally stop XXX threads every XXX seconds --------------多长时间停止多少线程,上图是在1s内停止10个线程(也就是全部)
OK,大致可以根据下方的图表看出来信息。
[Jmeter(三十四)Jmeter-Question之“Cookie获取”]
2018.4.27
还在做性能测试的过程中,唉,只能说坑很多。
无明确需求、无人手协调等问题,什么都需要自己去挖掘。
本次测试的工具选型依然是Jmeter,真实场景中遇到了这么个问题。可能解决办法有点笨拙,勉强算一次记录吧!
场景是这样:
每登录一次,便会生成token令牌。(注:该token令牌是在请求报文中的内容,非响应报文)
后边操作需要校验token令牌是否有效。
量较小时,可通过Ctrl+c、Ctrl+v完成。可是需求单位到了‘百’级别。
暂时性的解决办法是这样的:
jmeter配置文件jmeter.properties中有这么一段:
打开该属性。Cookie属性的值便会被保存下来。
使用debugSampler进行查看。
该COOKIE_token便可当做变量来进行使用。
我将获取到的token令牌写入了本地文件中。
将token令牌当做变量传过来,加入HttpCookie管理器中,完成此处的需求。
[Jmeter(三十五)聚合报告]
Jmeter的聚合报告是一个非常nice的listener,接口测试以及性能测试方面都会用到这个nice的监听器。
那么优秀在什么地方呢?上图
日常工作中可能只关注这部分内容:
可是这里边的指标真的都懂么?看了几篇知名大师的博客,都侧重谈了聚合报告这块的内容;当然,我在面试过程中,也经常有问在简历上写着“精通Jmeter”的面试者一些关于聚合报告方面的问题,遗憾,能回答上来的寥寥无几;或者说能答到重心的不多。可能本身这块的一个指标就存在一定的误区。
虽说在一些博客、公众号文章,一些大师用单独篇幅来讲解,貌似“后浪”并没有那么在意。又或者有关聚合报告方面的指标确实是容易给大家带来一些误导。
因此,我也着重来记一下聚合报告方面的内容。
和往常一样,先贴官方文档(有人经常吐槽看不懂英文,是硬伤总归是硬伤,慢慢补,当下为解燃眉之急,谷歌翻译、有道翻译等便是良策!):
帮助文档中清清楚楚的将每个指标都进行了诠释,可能某些翻译的原因或者自我认知的原因,都导致了一些误解。一一来进行解读吧。
Label:通俗一点的翻译是标签。(该标签通常争议不大)
【样品的标签。如果“在标签中包含组名?”然后,将线程组的名称作为前缀添加。这允许相同的标签从不同的线程组分开整理,如果需要的话。】(百度翻译)
#Samples:【相同标签的样本数】,请求数。
Average:平均响应时间。
1,2,3,4,5,6,7,8---这组数据的平均响应时间为45/8=5.625。
Median:中位数。
1,2,3,4,5,6,7,8,9---该组数据的中位数为5.
90%Line:【90%的样品不超过这个时间。剩下的样本至少和这个一样长。(第九十百分位数)】翻译何解?
通常有人将“90%Line”这个指标理解为90%用户的响应时间。
这个时候可以引申出来一个比较易理解的概念:众所周知,中国是一个人口大国,为衡量经济发展的情况,相关统计部门每年都会进行统计,xxx人已经实现脱贫(当然、具体标准就不扯了),那么这块的人数是怎么统计出来的呢?
当然、一个一个去统计是不现实的(当下),那么这个时候,90%Line指标就显得有效,同理,我们先带入进去,概念为“90%Line的平均响应时间”,按这个概念来讲,是完全不科学的;不能排除富到极点的人,也不能排除穷到极点的人,难道不是么?
0,1,2,3,4,5,6,7,8,9;90%的数为0,1,2,3,4,5,6,7,8,90%Line为(0+1+2+3+4+5+6+7+8)/9,这样的理解显然是不正确的。
那么,再代入翻译中的概念【90%的样品不超过这个时间】,假设0,1,2,3,4,5,6,7,8,9,90%Line的值为8,其言下之意为没有超过8的数都为“贫穷”,相比平均响应时间,可信度比较高。
95%Line:同上。
99%Line:同上。
Min:最小值。
Max:最大值
Error%:错误占比。
Throughput:吞吐量。
Received KB/sec:接收KB/SEC -以每秒接收千字节测量的吞吐量。
Sent KB/sec:发送KB/SEC -以每秒千字节发送的吞吐量。
[Jmeter(三十六)纵横并发、限制QPS]
一、纵横并发
Jmeter设计并发事件,这应该是一项必备技能。
首先来看并发的概念。
通常在性能测试中会涉及到并发用户数的概念,有关并发用户数(系统用户数)的详解后续再记。
(有关并发、并行的概念参考blog.csdn.net/qq_33290787…
并发:本质为一个CPU(或多个CPU)在若干道程序(或线程)之间的多路复用。
参考知乎大神的讲法:并发指的是该系统有处理多事务的能力,不一定是同时。
啃了啃虫师的一篇博客www.cnblogs.com/fnng/archiv…
文中对并发用户做了很详细的解释。其中更是对“真正意义上的并发不存在”一理论进行了很详细的阐述。推荐认真一阅。
那么在Jmeter中是如何进行模拟高仿并发的呢?
有人说了,用集合点,对,集合点确实达到并发目的的一个点。
还有人说了,不用集合点也可以,其实,对后者的观点,本人认为也是正确的,只是在某种意义上,设计该种场景的话要考虑的因素比较多。
废话不多说,先一一来上操作。
线程组加入线程数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 PanelParameters| 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
0is equivalent to setting it to Number of threads in Thread Group. | Yes | | Timeout in milliseconds | If set to0, Timer will wait for the number of threads to reach the value in "Number of Simultaneous Users to Group". If superior to0, 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 to0| No | | If timeout in milliseconds is set to0and 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的进行请求。
二、限制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 propertySee 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界面有两个选项:
1、期望吞吐量
2、以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的情况下,查看其响应时间等信息。
加入网上些许分析:(ydhome.blog.51cto.com/8948432/186…
1、这里的20 QPS应该是指Jmeter发送请求的QPS,而不是服务器处理的QPS;--因为假如我们以20 QPS的速度向服务器发送请求,但是服务器每秒最多只能处理8个请求,那么我们无论如何都无法测得服务器在20 QPS的情况下的性能数据;
2、难点在于让Jmeter【稳定地】以20 QPS的速度向服务器发送请求;
使用组件Constant Throughput Timer。
因为单位为minute(分钟),因此,需要20*60=1200。
加入listener,进行查看响应时间等信息。