【Locust分布式压力测试】

news/2024/4/30 3:28:17

Locust分布式压力测试

https://docs.locust.io/en/stable/running-distributed.html

在这里插入图片描述

Distributed load generation
A single process running Locust can simulate a reasonably high throughput. For a simple test plan and small payloads it can make more than a thousand requests per second, possibly over ten thousand if you use FastHttpUser.

But if your test plan is complex or you want to run even more load, you’ll need to scale out to multiple processes, maybe even multiple machines. Fortunately, Locust supports distributed runs out of the box.

To do this, you start one instance of Locust with the --master flag and one or more using the --worker flag. The master instance runs Locust’s web interface, and tells the workers when to spawn/stop Users. The worker instances run your Users and send statistics back to the master. The master instance doesn’t run any Users itself.

To simplify startup, you can use the --processes flag. It will launch a master process and the specified number of worker processes. It can also be used in combination with --worker, then it will only launch workers. This feature relies on fork() so it doesn’t work on Windows.

分布式发电
运行Locust的单个进程可以模拟相当高的吞吐量。对于一个简单的测试计划和较小的有效负载,它每秒可以发出超过一千个请求,如果使用fastttpuser,则可能超过一万个请求。

但是如果您的测试计划很复杂,或者您想要运行更多的负载,那么您将需要扩展到多个进程,甚至可能是多台机器。幸运的是,Locust支持开箱即用的分布式运行。

为此,使用——master标志启动一个Locust实例,使用——worker标志启动一个或多个Locust实例。主实例运行Locust的web界面,并告诉worker何时生成/停止user。工作实例运行用户并将统计数据发送回主实例。主实例本身不运行任何Users。

为了简化启动,可以使用——processes标志。它将启动一个主进程和指定数量的工作进程。它也可以与——worker结合使用,那么它只会启动worker。此功能依赖于fork(),因此在Windows上不起作用。

在这里插入图片描述

Because Python cannot fully utilize more than one core per process (see GIL), you need to run one worker instance per processor core in order to have access to all your computing power.
由于Python不能充分利用每个进程的多个内核(参见GIL),因此您需要为每个处理器内核运行一个工作实例,以便访问所有的计算能力。

在这里插入图片描述

There is almost no limit to how many Users you can run per worker. Locust/gevent can run thousands or even tens of thousands of Users per process just fine, as long as their total request rate (RPS) is not too high.
对于每个工作线程可以运行多少个用户,几乎没有限制。只要它们的总请求率(RPS)不太高,蝗虫/gevent可以在每个进程中运行数千甚至数万个用户。

If Locust is getting close to running out of CPU resources, it will log a warning. If there is no warning but you are still unable to generate the expected load, then the problem must be something else.
如果Locust即将耗尽CPU资源,它将记录一个警告。如果没有警告,但您仍然无法生成预期的负载,那么问题一定是别的。

**

locust spawn设置多少合适

**
Locust的并发用户数量是通过设置master节点上的–num-users和–spawn-rate参数来控制的。–num-users表示总的模拟用户数,–spawn-rate表示每秒启动的用户数。

设置多少个用户数和启动速率合适取决于几个因素:

系统资源:确保你的机器有足够的CPU和内存来支持更多的并发用户。目标系统:了解你测试的服务或系统的处理能力,确保不会超出其处理限制。测试目标:确定你想要模拟的用户负载类型和数量。

一般来说,设置合适的用户数和启动速率可以遵循以下步骤:

开始时设置较低的用户数和较高的启动速率,观察系统性能。当达到系统瓶颈,例如响应时间增加、错误率上升时,减少用户数或减慢启动速率。根据测试结果,逐渐增加用户数或启动速率,直到达到预期的性能指标或者资源使用达到瓶颈。

下面是一个示例命令,用于设置总共1000个用户,每秒启动200个用户:

locust --no-web --host=http://example.com --num-users=1000 --spawn-rate=200

这里使用了–no-web参数来表示不启动Web界面,直接在命令行运行测试。如果你想要使用Web界面,可以不加这个参数,并且在不指定用户数和启动速率的情况下直接启动Locust,然后在Web界面中进行配置。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.cpky.cn/p/11851.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

yolov9直接调用zed相机实现三维测距(python)

yolov9直接调用zed相机实现三维测距(python) 1. 相关配置2. 相关代码2.1 相机设置2.2 测距模块2.2 实验结果 相关链接 此项目直接调用zed相机实现三维测距,无需标定,相关内容如下: 1. yolov4直接调用zed相机实现三维测…

ROS2高效学习第十章 -- ros2 高级组件之大型项目中的 launch 其二

ros2 高级组件之大型项目中的 launch 1 前言和资料2 正文2.1 启动 turtlesim,生成一个 turtle ,设置背景色2.2 使用 event handler 重写上节的样例2.3 turtle_tf_mimic_rviz_launch 样例 3 总结 1 前言和资料 早在ROS2高效学习第四章 – ros2 topic 编程…

第十二届蓝桥杯省赛真题(C/C++大学B组)

目录 #A 空间 #B 卡片 #C 直线 #D 货物摆放 #E 路径 #F 时间显示 #G 砝码称重 #H 杨辉三角形 #I 双向排序 #J 括号序列 #A 空间 #include <bits/stdc.h> using namespace std;int main() {cout<<256 * 1024 * 1024 / 4<<endl;return 0; } #B 卡片…

JRT高效率开发

得益于前期的基础投入&#xff0c;借助代码生成的加持&#xff0c;本来计划用一周实现质控物维护界面&#xff0c;实际用来四小时左右完成质控物维护主体&#xff0c;效率大大超过预期。 JRT从设计之初就是为了证明Spring打包模式不适合软件服务模式&#xff0c;觉得Spring打包…

《前端防坑》- JS基础 - 你觉得typeof nullValue === null 么?

问题 JS原始类型有6种Undefined, Null, Number, String, Boolean, Symbol共6种。 在对原始类型使用typeof进行判断时, typeof stringValue string typeof numberValue number 如果一个变量(nullValue)的值为null&#xff0c;那么typeof nullValue "?" const u …

dp小兰走迷宫

昨天学习了bfs的基本概念&#xff0c;今天来做一道经典习题练练手吧&#xff01; bfs常用的两类题型 1.从A出发是否存在到达B的路径(dfs也可) 2.从A出发到B的最短路径&#xff08;数小:<20才能用dfs&#xff09; 遗留的那个问题的答案- 题目&#xff1a;走迷宫 #incl…