【转】Locust性能-零基础入门系列(3)-压力权重
本文将继续对Locust性能测试进行持续讲解,主要是讲解虚拟用户数分配和权重的关系。在locust file中进行多用户类的实现和操作。我们这次先上完整的代码:
from locust import User,between,task
import time class WebUser(User):
wait_time = between(5,9)
weight = 3
@task
def task_1(self):
nowTime = time.strftime("%Y-%m-%d %H:%M:%S")
print("This is a web user, test time is: "+nowTime) class MobileUser(User):
wait_time = between(5,9)
weight = 1
@task
def task_2(self):
nowTime = time.strftime("%Y-%m-%d %H:%M:%S")
print("This is a mobile user, test time is: "+nowTime)
代码分析。先从全局看,line 4和line 12是分别定义了2个用户类,这两个类都是继承User类。也都定义了wait_time属性。
在用户 WebUser中定义了一个任务方法task_1,在用户MobileUser中定义了一个任务方法 task_2。
其次是两个用户类中都定义了weight权重属性设置,其中WebUser为3(line 6), MobileUser为1(line 14)。
测试:
1)当模拟用户数为1时,测试log如下,可以发现这1个虚拟用户是作用在WebUser上的,而MobileUser上作用的虚拟用户数为0.所以,下面的log也没有MobileUser相关的任务被执行。
[2020-09-22 20:37:17,384] jasondeMacBook-Pro.local/INFO/locust.main: Starting Locust 1.1.1
[2020-09-22 20:37:23,794] jasondeMacBook-Pro.local/INFO/locust.runners: Hatching and swarming 1 users at the rate 1 users/s (0 users already running)...
[2020-09-22 20:37:23,794] jasondeMacBook-Pro.local/INFO/locust.runners: All users hatched: WebUser: 1, MobileUser: 0 (0 already running)
This is a web user, test time is: 2020-09-22 20:37:23
This is a web user, test time is: 2020-09-22 20:37:29
This is a web user, test time is: 2020-09-22 20:37:35
This is a web user, test time is: 2020-09-22 20:37:41
This is a web user, test time is: 2020-09-22 20:37:48
This is a web user, test time is: 2020-09-22 20:37:57
This is a web user, test time is: 2020-09-22 20:38:04
This is a web user, test time is: 2020-09-22 20:38:12
2)当模拟用户数为2时,测试log如下,发现这2个用户都是作用在WebUser上的。
[2020-09-22 21:11:42,893] jasondeMacBook-Pro.local/INFO/locust.main: Starting web interface at http://:8089
[2020-09-22 21:11:42,899] jasondeMacBook-Pro.local/INFO/locust.main: Starting Locust 1.1.1
[2020-09-22 21:11:49,142] jasondeMacBook-Pro.local/INFO/locust.runners: Hatching and swarming 2 users at the rate 1 users/s (0 users already running)...
This is a web user, test time is: 2020-09-22 21:11:49
[2020-09-22 21:11:50,147] jasondeMacBook-Pro.local/INFO/locust.runners: All users hatched: WebUser: 2, MobileUser: 0 (0 already running)
This is a web user, test time is: 2020-09-22 21:11:50
This is a web user, test time is: 2020-09-22 21:11:57
This is a web user, test time is: 2020-09-22 21:11:57
3)当模拟用户数为4时,测试log如下,发现有3个用户作用在WebUser,1个用户作用在MobileUser上。
[2020-09-22 21:13:24,883] jasondeMacBook-Pro.local/INFO/locust.main: Starting web interface at http://:8089
[2020-09-22 21:13:24,892] jasondeMacBook-Pro.local/INFO/locust.main: Starting Locust 1.1.1
[2020-09-22 21:13:29,896] jasondeMacBook-Pro.local/INFO/locust.runners: Hatching and swarming 4 users at the rate 1 users/s (0 users already running)...
This is a web user, test time is: 2020-09-22 21:13:29
This is a web user, test time is: 2020-09-22 21:13:30
This is a web user, test time is: 2020-09-22 21:13:31
[2020-09-22 21:13:32,899] jasondeMacBook-Pro.local/INFO/locust.runners: All users hatched: WebUser: 3, MobileUser: 1 (0 already running)
This is a mobile user, test time is: 2020-09-22 21:13:32
This is a web user, test time is: 2020-09-22 21:13:37
This is a web user, test time is: 2020-09-22 21:13:37
This is a web user, test time is: 2020-09-22 21:13:38
This is a mobile user, test time is: 2020-09-22 21:13:41
总结:
1)一个场景文件中可以定义多个用户类,方便对业务逻辑进行分类处理。并且可以为多个用户类设置权重。
2)如果用户类权重不足1人,则会被忽略,如测试第1,2中情况。
【转】Locust性能-零基础入门系列(3)-压力权重的更多相关文章
- 【转】Locust性能-零基础入门系列(1)-wait_time属性用法
本篇文章,从局部出发,利用一个简单的测试,来说明场景模拟的wait_time属性的用法.wait_time为什么要单独拎出来讲,是因为它主要有两种模式,而初学者对这两种模式,容易混淆.1) wait_ ...
- 【转】Locust性能-零基础入门系列(2) -重写wait_time
在虚拟模拟的时候,可能对等待时间有更高的要求,比如假如有这么一个场景要求:某任务要求每被执行1次,那么下次的等待时间就1秒钟.这种情况,是可以实现的,这也就体现了Locust的灵活性.可编程性,很多比 ...
- 【JAVA零基础入门系列】Day13 Java类的继承与多态
继承是类的一个很重要的特性,什么?你连继承都不知道?你是想气死爸爸好继承爸爸的遗产吗?(滑稽) 开个玩笑,这里的继承跟我们现实生活的中继承还是有很大区别的,一个类可以继承另一个类,继承的内容包括属性跟 ...
- 【JAVA零基础入门系列】Day2 Java集成开发环境IDEA
开发环境搭建好之后,还需要一个集成开发环境也就是IDE来进行编程.这里推荐的IDE是IDEA,那个老掉牙的Eclipse还是先放一边吧,(手动滑稽). IDEA的下载地址:http://www.jet ...
- 【JAVA零基础入门系列】Day4 变量与常量
这一篇主要讲解Java中的变量,什么是变量,变量的作用以及如何声明,使用变量. 那么什么是变量?对于初学者而言,可以将变量理解为盒子,这些盒子可以用来存放数据,不同类型的数据需要放在对应类型的盒子里. ...
- 【JAVA零基础入门系列】Day5 Java中的运算符
运算符,顾名思义就是用于运算的符号,比如最简单的+-*/,这些运算符可以用来进行数学运算,举个最简单的栗子: 已知长方形的长为3cm,高为4cm,求长方形的面积. 好,我们先新建一个项目,命名为Rec ...
- 【JAVA零基础入门系列】Day6 Java字符串
字符串,是我们最常用的类型,每个用双引号来表示的串都是一个字符串.Java中的字符串是一个预定义的类,跟C++ 一样叫String,而不是Char数组.至于什么叫做类,暂时不做过多介绍,在之后的篇章中 ...
- 【JAVA零基础入门系列】Day8 Java的控制流程
什么是控制流程?简单来说就是控制程序运行逻辑的,因为程序一般而言不会直接一步运行到底,而是需要加上一些判断,一些循环等等.举个栗子,就好比你准备出门买个苹果,把这个过程当成程序的话,可能需要先判断一下 ...
- 【JAVA零基础入门系列】Day9 Java中的那个大数值
什么是大数值?用脚趾头想也知道,当然是"大"的数值(233).Java中有两个用于表示大数值的类,BigInteger和BigDecimal,那到底能表示多大的数值呢?理论上,可以 ...
随机推荐
- 玩转Spring——Spring整合JDBC
传统JDBC代码的弊端在传统的jdbc代码中,即使是执行一条简单的SQL语句,其实现的整个流程也是极为繁琐的,先打开数据库连接执行sql,然后组装结果,最后关闭数据库资源,这中间还有大量的try... ...
- 10分钟搞定 Java 并发队列好吗?好的
| 好看请赞,养成习惯 你有一个思想,我有一个思想,我们交换后,一个人就有两个思想 If you can NOT explain it simply, you do NOT understand it ...
- Windows & Linux 安装使用 Vim 编辑器 3分钟入门 - 精简归纳
Windows & Linux 安装使用 Vim 编辑器 3分钟入门 - 精简归纳 JERRY_Z. ~ 2020 / 8 / 25 转载请注明出处! 目录 Windows & Lin ...
- @RequestBody和@RequestParam
@RequestBody的使用 https://blog.csdn.net/justry_deng/article/details/80972817 (@RequestBody Map map)接收多 ...
- C#可空类型 T?
可空类型概述 可空类型具有以下特性: 可空类型表示可被赋值为 null 值的值类型变量.无法创建基于引用类型的可空类型.(引用类型已支持 null 值.). 语法 T? 是 System.Nullab ...
- WebStorm下ReactNative代码提示设置
ReactNative 代码智能提醒 (Webstrom live template) https://github.com/virtoolswebplayer/ReactNative-LiveTe ...
- java返回树形结构的正确姿势
业务场景 通常我们前端需要一个树形的导航菜单或者分类菜单,如后台权限管理中的权限树,亦或者下面例子中商城系统的商品分类多级菜单(一般为三级菜单) 数据库设计 数据库设计,采用parentId来指向自己 ...
- 【jmespath】—1. 基础用法
一.jsonpath 之前我写接口自动化测试时候,对于复杂的json返回,会使用jsonpath这个第三方库,就像写xpath一样,方便的查询json元素. 因为之前写WEB自动化时候,总用xpath ...
- vue 多环境打包
https://cli.vuejs.org/zh/guide/mode-and-env.html#%E6%A8%A1%E5%BC%8F 模式 模式是 Vue CLI 项目中一个重要的概念.默认情况下, ...
- 每日一道 LeetCode (41):阶乘后的零
每天 3 分钟,走上算法的逆袭之路. 前文合集 每日一道 LeetCode 前文合集 代码仓库 GitHub: https://github.com/meteor1993/LeetCode Gitee ...