一、纵横并发

Jmeter设计并发事件,这应该是一项必备技能。

首先来看并发的概念。

通常在性能测试中会涉及到并发用户数的概念,有关并发用户数(系统用户数)的详解后续再记。

(有关并发、并行的概念参考https://blog.csdn.net/qq_33290787/article/details/51790605)

并发:本质为一个CPU(或多个CPU)在若干道程序(或线程)之间的多路复用。

参考知乎大神的讲法:并发指的是该系统有处理多事务的能力,不一定是同时。

啃了啃虫师的一篇博客http://www.cnblogs.com/fnng/archive/2012/06/25/2562943.html--并发用户。

文中对并发用户做了很详细的解释。其中更是对“真正意义上的并发不存在”一理论进行了很详细的阐述。推荐认真一阅。

那么在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 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的进行请求。

二、限制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界面有两个选项:

  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的情况下,查看其响应时间等信息。

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

1、这里的20 QPS应该是指Jmeter发送请求的QPS,而不是服务器处理的QPS;--因为假如我们以20 QPS的速度向服务器发送请求,但是服务器每秒最多只能处理8个请求,那么我们无论如何都无法测得服务器在20 QPS的情况下的性能数据;

2、难点在于让Jmeter【稳定地】以20 QPS的速度向服务器发送请求;

使用组件Constant Throughput Timer。

因为单位为minute(分钟),因此,需要20*60=1200。

加入listener,进行查看响应时间等信息。

Jmeter(三十六)纵横并发、限制QPS的更多相关文章

  1. Python之路(第三十六篇)并发编程:进程、同步异步、阻塞非阻塞

    一.理论基础 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统的其他所有内容都是围绕进程的概念展开的. 即使可以利用的cpu只有一个(早期的 ...

  2. Jmeter(三十六) - 从入门到精通进阶篇 - 设置负载阶梯式压测场景(详解教程)

    1.简介 在性能测试中,有时需要模拟一种实际生产中经常出现的情况,即:从某个值开始不断增加压力,直至达到某个值,然后持续运行一段时间,然后继续加压达到某个值持续运行,如此循环直到达到预期的峰值,运行一 ...

  3. Jmeter(三十六)_运行过程中改变负载

    顾名思义,jmeter在做性能测试时,可以在不停止脚本的情况下修改负载压力,达到期望的测试效果.我们将通过Constant Throughput Timer(吞吐量计时器)和Beanshell服务器来 ...

  4. 程序员编程艺术第三十六~三十七章、搜索智能提示suggestion,附近点搜索

    第三十六~三十七章.搜索智能提示suggestion,附近地点搜索 作者:July.致谢:caopengcs.胡果果.时间:二零一三年九月七日. 题记 写博的近三年,整理了太多太多的笔试面试题,如微软 ...

  5. NeHe OpenGL教程 第三十六课:从渲染到纹理

    转自[翻译]NeHe OpenGL 教程 前言 声明,此 NeHe OpenGL教程系列文章由51博客yarin翻译(2010-08-19),本博客为转载并稍加整理与修改.对NeHe的OpenGL管线 ...

  6. Java进阶(三十六)深入理解Java的接口和抽象类

    Java进阶(三十六)深入理解Java的接口和抽象类 前言 对于面向对象编程来说,抽象是它的一大特征之一.在Java中,可以通过两种形式来体现OOP的抽象:接口和抽象类.这两者有太多相似的地方,又有太 ...

  7. Gradle 1.12用户指南翻译——第三十六章. Sonar Runner 插件

    本文由CSDN博客万一博主翻译,其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Githu ...

  8. 第三百三十六节,web爬虫讲解2—urllib库中使用xpath表达式—BeautifulSoup基础

    第三百三十六节,web爬虫讲解2—urllib库中使用xpath表达式—BeautifulSoup基础 在urllib中,我们一样可以使用xpath表达式进行信息提取,此时,你需要首先安装lxml模块 ...

  9. centos shell脚本编程2 if 判断 case判断 shell脚本中的循环 for while shell中的函数 break continue test 命令 第三十六节课

    centos  shell脚本编程2 if 判断  case判断   shell脚本中的循环  for   while   shell中的函数  break  continue  test 命令   ...

  10. “全栈2019”Java第三十六章:类

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

随机推荐

  1. Spring boot Mybatis 整合

    PS: 参考博客 PS: spring boot配置mybatis和事务管理 PS: Spring boot Mybatis 整合(完整版)   这篇博客里用到了怎样 生成 mybatis 插件来写程 ...

  2. svelte 构建快速web 应用的工具

    svelte 和angular vue reat 类似,都是方便快速的创建用户界面,最大不同的地方是svelte 转换你的app 是在构建时,而不是运行时,所以好处就是不用花费太多的操作在,框架的 抽 ...

  3. python时间戳转时间

    import time timestamp = 1462451334 #转换成localtime time_local = time.localtime(timestamp) #转换成新的时间格式(2 ...

  4. 大数据框架对比:Hadoop、Storm、Samza、Spark和Flink--容错机制(ACK,RDD,基于log和状态快照),消息处理at least once,exactly once两个是关键

    分布式流处理是对无边界数据集进行连续不断的处理.聚合和分析.它跟MapReduce一样是一种通用计算,但我们期望延迟在毫秒或者秒级别.这类系统一般采用有向无环图(DAG). DAG是任务链的图形化表示 ...

  5. LOJ 3055 「HNOI2019」JOJO—— kmp自动机+主席树

    题目:https://loj.ac/problem/3055 先写了暴力.本来想的是 n<=300 的那个在树上暴力维护好整个字符串, x=1 的那个用主席树维护好字符串和 nxt 数组.但 x ...

  6. oracle误删数据

    表名:SYS_MENU alter table SYS_MENU enable row movementflashback table SYS_MENU to timestamp to_timesta ...

  7. NVMe标准规范

    NVMe NVM Express(NVMe),或称非易失性内存主机控制器接口规范(Non-Volatile Memory express),,是一个逻辑设备接口规范.他是与AHCI类似的.基于设备逻辑 ...

  8. VS2012打开项目——已停止工作

    VS2012打开项目——已停止工作 解决方法如下: 1. 开始-->所有程序-->Microsoft Visual Studio 2012-->Visual Studio Tools ...

  9. Windows右键菜单中新建项目添加与删除

    一种是如  txt 类型: HKEY_CLASSES_ROOT\.txt\ShellNew 项下空字符串值:NullFile 另一种如MsOffice类型: HKEY_CLASSES_ROOT\.xl ...

  10. [Android] 配置build.gradle 动态传参

    (1)一个Android工程中有一个build.gradle是负责Project范围的,而Module中又有各自的build.gradle是专门负责模块的. (2)在Gradle中Task是一等公民, ...