locust之执行方式

2024-03-09 21:08
文章标签 方式 执行 locust

本文主要是介绍locust之执行方式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.命令行执行方式

如:locust -f example.py --host http://192.168.2.129 -u 2 -r 1 -t 10m --headless

$ locust --helpUsage: locust [OPTIONS] [UserClass ...]Common options:-h, --help            show this help message and exit-f LOCUSTFILE, --locustfile LOCUSTFILEPython module file to import, e.g. '../other.py'.Default: locustfile--config CONFIG       Config file path-H HOST, --host HOST  Host to load test in the following format:http://10.21.32.33-u NUM_USERS, --users NUM_USERSNumber of concurrent Locust users. Primarily usedtogether with --headless. Can be changed during a testby inputs w, W(spawn 1, 10 users) and s, S(stop 1, 10users)-r SPAWN_RATE, --spawn-rate SPAWN_RATEThe rate per second in which users are spawned.Primarily used together with --headless-t RUN_TIME, --run-time RUN_TIMEStop after the specified amount of time, e.g. (300s,20m, 3h, 1h30m, etc.). Only used together with--headless. Defaults to run forever.-l, --list            Show list of possible User classes and exitWeb UI options:--web-host WEB_HOST   Host to bind the web interface to. Defaults to '*'(all interfaces)--web-port WEB_PORT, -P WEB_PORTPort on which to run web host--headless            Disable the web interface, and instead start the loadtest immediately. Requires -u and -t to be specified.--web-auth WEB_AUTH   Turn on Basic Auth for the web interface. Should besupplied in the following format: username:password--tls-cert TLS_CERT   Optional path to TLS certificate to use to serve overHTTPS--tls-key TLS_KEY     Optional path to TLS private key to use to serve overHTTPSMaster options:Options for running a Locust Master node when running Locust distributed. A Master node need Worker nodes that connect to it before it can run load tests.--master              Set locust to run in distributed mode with thisprocess as master--master-bind-host MASTER_BIND_HOSTInterfaces (hostname, ip) that locust master shouldbind to. Only used when running with --master.Defaults to * (all available interfaces).--master-bind-port MASTER_BIND_PORTPort that locust master should bind to. Only used whenrunning with --master. Defaults to 5557.--expect-workers EXPECT_WORKERSHow many workers master should expect to connectbefore starting the test (only when --headless used).Worker options:Options for running a Locust Worker node when running Locust distributed.Only the LOCUSTFILE (-f option) need to be specified when starting a Worker, since other options such as -u, -r, -t are specified on the Master node.--worker              Set locust to run in distributed mode with thisprocess as worker--master-host MASTER_NODE_HOSTHost or IP address of locust master for distributedload testing. Only used when running with --worker.Defaults to 127.0.0.1.--master-port MASTER_NODE_PORTThe port to connect to that is used by the locustmaster for distributed load testing. Only used whenrunning with --worker. Defaults to 5557.Tag options:Locust tasks can be tagged using the @tag decorator. These options let specify which tasks to include or exclude during a test.-T [TAG [TAG ...]], --tags [TAG [TAG ...]]List of tags to include in the test, so only taskswith any matching tags will be executed-E [TAG [TAG ...]], --exclude-tags [TAG [TAG ...]]List of tags to exclude from the test, so only taskswith no matching tags will be executedRequest statistics options:--csv CSV_PREFIX      Store current request stats to files in CSV format.Setting this option will generate three files:[CSV_PREFIX]_stats.csv, [CSV_PREFIX]_stats_history.csvand [CSV_PREFIX]_failures.csv--csv-full-history    Store each stats entry in CSV format to_stats_history.csv file. You must also specify the '--csv' argument to enable this.--print-stats         Print stats in the console--only-summary        Only print the summary stats--reset-stats         Reset statistics once spawning has been completed.Should be set on both master and workers when runningin distributed mode--html HTML_FILE      Store HTML report fileLogging options:--skip-log-setup      Disable Locust's logging setup. Instead, theconfiguration is provided by the Locust test or Pythondefaults.--loglevel LOGLEVEL, -L LOGLEVELChoose between DEBUG/INFO/WARNING/ERROR/CRITICAL.Default is INFO.--logfile LOGFILE     Path to log file. If not set, log will go tostdout/stderrOther options:--show-task-ratio     Print table of the User classes' task execution ratio--show-task-ratio-jsonPrint json data of the User classes' task executionratio--version, -V         Show program's version number and exit--exit-code-on-error EXIT_CODE_ON_ERRORSets the process exit code to use when a test resultcontain any failure or error-s STOP_TIMEOUT, --stop-timeout STOP_TIMEOUTNumber of seconds to wait for a simulated user tocomplete any executing task before exiting. Default isto terminate immediately. This parameter only needs tobe specified for the master process when runningLocust distributed.User classes:UserClass             Optionally specify which User classes that should beused (available User classes can be listed with -l or--list)

2.配置文件方式,将所有运行参数写入配置文件locust.conf

在配置文件所在目录命令行直接运行locust,就会自动执行配置文件,也可以通过--config参数指定配置文件。

配置文件优先级:

~/locust.conf -> ./locust.conf -> (file specified using --conf) -> env vars -> cmd args

Example:

# master.conf in current directory
locustfile = locust_files/my_locust_file.py
headless = true
master = true
expect-workers = 5
host = http://target-system
users = 100
spawn-rate = 10
run-time = 10m

 

3.webUI方式

命令行执行locust -f .\example_task_queue.py

根据提示打开浏览器,输入地址连接http://localhost:8089

输入测试的用户数,启动用户需要的时间和服务器地址,点击按钮Start swarming,测试就会自动开始执行。

进入主界面可以看到测试实时的统计,点击按钮STOP可以停止测试。

测试结果可以导出。

 

 

 

这篇关于locust之执行方式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/791951

相关文章

gitlab安装及邮箱配置和常用使用方式

《gitlab安装及邮箱配置和常用使用方式》:本文主要介绍gitlab安装及邮箱配置和常用使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1.安装GitLab2.配置GitLab邮件服务3.GitLab的账号注册邮箱验证及其分组4.gitlab分支和标签的

C++中零拷贝的多种实现方式

《C++中零拷贝的多种实现方式》本文主要介绍了C++中零拷贝的实现示例,旨在在减少数据在内存中的不必要复制,从而提高程序性能、降低内存使用并减少CPU消耗,零拷贝技术通过多种方式实现,下面就来了解一下... 目录一、C++中零拷贝技术的核心概念二、std::string_view 简介三、std::stri

Linux脚本(shell)的使用方式

《Linux脚本(shell)的使用方式》:本文主要介绍Linux脚本(shell)的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录概述语法详解数学运算表达式Shell变量变量分类环境变量Shell内部变量自定义变量:定义、赋值自定义变量:引用、修改、删

python判断文件是否存在常用的几种方式

《python判断文件是否存在常用的几种方式》在Python中我们在读写文件之前,首先要做的事情就是判断文件是否存在,否则很容易发生错误的情况,:本文主要介绍python判断文件是否存在常用的几种... 目录1. 使用 os.path.exists()2. 使用 os.path.isfile()3. 使用

Mybatis的分页实现方式

《Mybatis的分页实现方式》MyBatis的分页实现方式主要有以下几种,每种方式适用于不同的场景,且在性能、灵活性和代码侵入性上有所差异,对Mybatis的分页实现方式感兴趣的朋友一起看看吧... 目录​1. 原生 SQL 分页(物理分页)​​2. RowBounds 分页(逻辑分页)​​3. Page

Linux链表操作方式

《Linux链表操作方式》:本文主要介绍Linux链表操作方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、链表基础概念与内核链表优势二、内核链表结构与宏解析三、内核链表的优点四、用户态链表示例五、双向循环链表在内核中的实现优势六、典型应用场景七、调试技巧与

Linux实现线程同步的多种方式汇总

《Linux实现线程同步的多种方式汇总》本文详细介绍了Linux下线程同步的多种方法,包括互斥锁、自旋锁、信号量以及它们的使用示例,通过这些同步机制,可以解决线程安全问题,防止资源竞争导致的错误,示例... 目录什么是线程同步?一、互斥锁(单人洗手间规则)适用场景:特点:二、条件变量(咖啡厅取餐系统)工作流

RedisTemplate默认序列化方式显示中文乱码的解决

《RedisTemplate默认序列化方式显示中文乱码的解决》本文主要介绍了SpringDataRedis默认使用JdkSerializationRedisSerializer导致数据乱码,文中通过示... 目录1. 问题原因2. 解决方案3. 配置类示例4. 配置说明5. 使用示例6. 验证存储结果7.

Python程序打包exe,单文件和多文件方式

《Python程序打包exe,单文件和多文件方式》:本文主要介绍Python程序打包exe,单文件和多文件方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录python 脚本打成exe文件安装Pyinstaller准备一个ico图标打包方式一(适用于文件较少的程

Python验证码识别方式(使用pytesseract库)

《Python验证码识别方式(使用pytesseract库)》:本文主要介绍Python验证码识别方式(使用pytesseract库),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全... 目录1、安装Tesseract-OCR2、在python中使用3、本地图片识别4、结合playwrigh