Locust 官方文档 4:配置运行选项

Command Line Options

The most straight forward way to Configure how Locust is run is through command line arguments.

配置 Locust 运行方式的最直接方法是通过命令行参数:

$ locust --help
Usage: locust [OPTIONS] [UserClass ...]

Common options:
  -h, --help            show this help message and exit  查看帮助信息并退出
  -f LOCUSTFILE, --locustfile LOCUSTFILE
                        Python module file to import, e.g. '../other.py'.  指定 locust 文件
                        Default: locustfile
  --config CONFIG       Config file path 指定配置文件
  -H HOST, --host HOST  Host to load test in the following format: 指定测试系统的 host
                        http://10.21.32.33
  -u NUM_USERS, --users NUM_USERS 测试的虚拟用户数,仅与 `--headless` 参数一起使用
                        Number of concurrent Locust users. Only used together
                        with --headless
  -r HATCH_RATE, --hatch-rate HATCH_RATE  每秒产生用户的速率,仅与 `--headless` 参数一起使用
                        The rate per second in which users are spawned. Only
                        used together with --headless
  -t RUN_TIME, --run-time RUN_TIME  在指定时间后停止测试,例如 (300s,
                        20m, 3h, 1h30m, etc.),仅与 `--headless` 参数一起使用
                        Stop after the specified amount of time, e.g. (300s,
                        20m, 3h, 1h30m, etc.). Only used together with
                        --headless
  -l, --list            Show list of possible User classes and exit 显示可能的 User 类别列表并退出

Web UI options:
  --web-host WEB_HOST   Host to bind the web interface to. Defaults to '*'
                        (all interfaces) 绑定 web 界面到 host,默认使用 `*`(所有界面)
  --web-port WEB_PORT, -P WEB_PORT  Web 界面的运行端口
                        Port on which to run web host
  --headless            Disable the web interface, and instead start the load
                        test immediately. Requires -u and -t to be specified.
                        禁用 Web 界面,然后立即开始负载测试。需要指定 -u 和 -t。
  --web-auth WEB_AUTH   Turn on Basic Auth for the web interface. Should be
                        supplied in the following format: username:password
                        给 Web 界面设置 Basic Auth。必须提供:username:password。
                        设置后,打开 Locust 的 web 界面必须要输入账号密码
  --tls-cert TLS_CERT   Optional path to TLS certificate to use to serve over
                        HTTPS
                        对于使用 HTTPS 的服务,提供服务的 TLS 证书的路径
  --tls-key TLS_KEY     Optional path to TLS private key to use to serve over
                        HTTPS
                        对于使用 HTTPS 的服务,提供服务的 TLS 私钥的路径

Master 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.
  运行 Locust 分布式时运行 Locust Master节点的选项。主节点需要连接到它的辅助节点,然后它才能运行负载测试。

  --master              Set locust to run in distributed mode with this
                        process as master
                        设置 Locust 运行时的主节点
  --master-bind-host MASTER_BIND_HOST
                        Interfaces (hostname, ip) that locust master should
                        bind to. Only used when running with --master.
                        Defaults to * (all available interfaces).
                        Locust 主节点的接口(host,IP)。仅在与 --master 一起运行时使用。
                        默认为 *。
  --master-bind-port MASTER_BIND_PORT
                        Port that locust master should bind to. Only used when
                        running with --master. Defaults to 5557.
                        Locust 主节点的端口,默认使用 5557,仅在与 --master 一起运行时使用
  --expect-workers EXPECT_WORKERS
                        How many workers master should expect to connect
                        before starting the test (only when --headless used).
                        在测试之前指定拥有多少个工作节点。(仅在与 --master 一起运行时使用)

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.
  运行 Locust 分布式运行的工作节点选项。
  启动工作节点时,仅需要指定 locustfile(-f 选项),因为在其他选项(例如-u,-r,-t)是通过主节点指定。

  --worker              Set locust to run in distributed mode with this
                        process as worker
                        在 Locust 分布式运行时,使用此参数指定当前 PC 为工作节点
  --master-host MASTER_HOST
                        Host or IP address of locust master for distributed
                        load testing. Only used when running with --worker.
                        Defaults to 127.0.0.1.
                        指定 Locust 分布式执行的主节点地址。仅当与 --worker 参数同时运行时有效。
                        默认为 127.0.0.1
  --master-port MASTER_PORT
                        The port to connect to that is used by the locust
                        master for distributed load testing. Only used when
                        running with --worker. Defaults to 5557.
                        Locust 分布式运行时的主节点端口,仅在与 --worker 同时运行时有效。
                        默认为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.
  可以使用 @tag 装饰器对 Locust 任务进行标记。这些选项使您可以指定在测试期间要包括或排除的任务。

  -T [TAG [TAG ...]], --tags [TAG [TAG ...]]
                        List of tags to include in the test, so only tasks
                        with any matching tags will be executed
                        要包含在测试中的标签列表,只有被包含的标签标记的任务才会被执行
  -E [TAG [TAG ...]], --exclude-tags [TAG [TAG ...]]
                        List of tags to exclude from the test, so only tasks
                        with no matching tags will be executed
                        要排除的标签列表,被指定的标签标记的任务在测试中不会被执行

Request statistics options:
请求统计信息选项:
  --csv CSV_PREFIX      Store current request stats to files in CSV format.
                        Setting this option will generate three files:
                        将当前统计信息存储在 CSV 文件中,使用此选项会生成以下三个文件:
                        [CSV_PREFIX]_stats.csv, [CSV_PREFIX]_stats_history.csv
                        and [CSV_PREFIX]_failures.csv
  --csv-full-history    Store each stats entry in CSV format to
                        _stats_history.csv file
                        将每个统计信息条目以 CSV 格式存储到 _stats_history.csv
  --print-stats         Print stats in the console  将统计信息打印到控制台
  --only-summary        Only print the summary stats  仅打印统计信息
  --reset-stats         Reset statistics once hatching has been completed.
                        Should be set on both master and workers when running
                        in distributed mode
                        测试完成后重置统计信息。在分布式模式下应同时设置主节点和工作节点

Logging options:
日志选项:
  --skip-log-setup      Disable Locust's logging setup. Instead, the
                        configuration is provided by the Locust test or Python
                        defaults.
                        禁用 Locust 日志。相反,配置由 Locust 测试或 Python 提供默认值。
  --loglevel LOGLEVEL, -L LOGLEVEL
                        Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL.
                        Default is INFO.
                        选择日志级别,默认为 INFO
  --logfile LOGFILE     Path to log file. If not set, log will go to
                        stdout/stderr
                        指定存放日志的文件路径。如果不设,日志仅显示在标准输出/标准错误

Step load options:
Step 加载选项:
  --step-load           Enable Step Load mode to monitor how performance
                        metrics varies when user load increases. Requires
                        --step-users and --step-time to be specified.
                        启用逐步加载模式以监视性能指标随着用户负载的增加而变化。
                        需要同时指定 --step-users 和 --step-time。
  --step-users STEP_USERS
                        User count to increase by step in Step Load mode. Only
                        used together with --step-load
                        在逐步加载模式下,每步增加的用户数量。仅与 --step-load 一起使用
                        
  --step-time STEP_TIME
                        Step duration in Step Load mode, e.g. (300s, 20m, 3h,
                        1h30m, etc.). Only used together with --step-load
                        逐步加载模式下,每步持续时间,例如(300s,20m,3h,1h30m等)。
                        仅与--step-load一起使用

Other options:
其他选项:
  --show-task-ratio     Print table of the User classes' task execution ratio. 打印 User 类的任务执行率
  --show-task-ratio-json
                        Print json data of the User classes' task execution
                        ratio
                        打印 User 类的任务执行率的 json 数据
  --version, -V         Show program's version number and exit 显示 Locust 版本并退出
  --exit-code-on-error EXIT_CODE_ON_ERROR
                        Sets the process exit code to use when a test result
                        contain any failure or error
                        当测试结果包含失败或错误时,设置程序的退出码
  -s STOP_TIMEOUT, --stop-timeout STOP_TIMEOUT
                        Number of seconds to wait for a simulated user to
                        complete any executing task before exiting. Default is
                        to terminate immediately. This parameter only needs to
                        be specified for the master process when running
                        Locust distributed.
                       虚拟用户在执行完成后退出等待的时间。默认为立即停止。
                       分布式执行时,只需要在主进程中指定即可。
                       
User classes:
  UserClass             Optionally specify which User classes that should be
                        used (available User classes can be listed with -l or
                        --list)
                       (可选)指定哪些 User 类可使用(可用的 User 类可以用 -l 或 --list)

环境变量

Most of the options that can be set through command line arguments can also be set through environment variables. Example:

可以通过命令行参数设置的大多数选项也可以通过环境变量设置。例如:

配置文件

Any of the options that can be set through command line arguments can also be set by a configuration file in the config file format.

可以通过命令行配置各项参数,也可以使用配置文件 config file 进行配置。

Locust will look for ~/.locust.conf and ./locust.conf by default, and you can specify an additional file using the --config flag.

Locust 默认会查找 ~/.locust.conf./locust.conf 作为配置文件,也可以使用 --config 参数指定文件。

Example:

$ locust --config=master.conf

Note

Configuration values are read (overridden) in the following order:

注意:配置值会按如下顺序读取

所有有效的配置项

Here’s a table of all the available configuration options, and their corresponding Environment and config file keys:

下表列出了所有可用的配置选项及其对应的环境和配置文件键值:

Command line Environment Config file Description
-f, --locustfile LOCUST_LOCUSTFILE locustfile Python module file to import, e.g. ‘../other.py’. Default: locustfile
-H, --host LOCUST_HOST host Host to load test in the following format: http://10.21.32.33
-u, --users LOCUST_USERS users Number of concurrent Locust users. Only used together with –headless
-r, --hatch-rate LOCUST_HATCH_RATE hatch-rate The rate per second in which users are spawned. Only used together with –headless
-t, --run-time LOCUST_RUN_TIME run-time Stop after the specified amount of time, e.g. (300s, 20m, 3h, 1h30m, etc.). Only used together with –headless
--web-host LOCUST_WEB_HOST web-host Host to bind the web interface to. Defaults to ‘*’ (all interfaces)
--web-port, -P LOCUST_WEB_PORT web-port Port on which to run web host
--headless LOCUST_HEADLESS headless Disable the web interface, and instead start the load test immediately. Requires -u and -t to be specified.
--web-auth LOCUST_WEB_AUTH web-auth Turn on Basic Auth for the web interface. Should be supplied in the following format: username:password
--tls-cert LOCUST_TLS_CERT tls-cert Optional path to TLS certificate to use to serve over HTTPS
--tls-key LOCUST_TLS_KEY tls-key Optional path to TLS private key to use to serve over HTTPS
--master LOCUST_MODE_MASTER master Set locust to run in distributed mode with this process as master
--master-bind-host LOCUST_MASTER_BIND_HOST master-bind-host Interfaces (hostname, ip) that locust master should bind to. Only used when running with –master. Defaults to * (all available interfaces).
--master-bind-port LOCUST_MASTER_BIND_PORT master-bind-port Port that locust master should bind to. Only used when running with –master. Defaults to 5557.
--expect-workers LOCUST_EXPECT_WORKERS expect-workers How many workers master should expect to connect before starting the test (only when –headless used).
--worker LOCUST_MODE_WORKER worker Set locust to run in distributed mode with this process as worker
--master-host LOCUST_MASTER_NODE_HOST master-host Host or IP address of locust master for distributed load testing. Only used when running with –worker. Defaults to 127.0.0.1.
--master-port LOCUST_MASTER_NODE_PORT master-port The port to connect to that is used by the locust master for distributed load testing. Only used when running with –worker. Defaults to 5557.
-T, --tags LOCUST_TAGS tags List of tags to include in the test, so only tasks with any matching tags will be executed
-E, --exclude-tags LOCUST_EXCLUDE_TAGS exclude-tags List of tags to exclude from the test, so only tasks with no matching tags will be executed
--csv LOCUST_CSV csv Store current request stats to files in CSV format. Setting this option will generate three files: [CSV_PREFIX]_stats.csv, [CSV_PREFIX]_stats_history.csv and [CSV_PREFIX]_failures.csv
--csv-full-history LOCUST_CSV_FULL_HISTORY csv-full-history Store each stats entry in CSV format to _stats_history.csv file
--print-stats LOCUST_PRINT_STATS print-stats Print stats in the console
--only-summary LOCUST_ONLY_SUMMARY only-summary Only print the summary stats
--reset-stats LOCUST_RESET_STATS reset-stats Reset statistics once hatching has been completed. Should be set on both master and workers when running in distributed mode
--skip-log-setup LOCUST_SKIP_LOG_SETUP skip-log-setup Disable Locust’s logging setup. Instead, the configuration is provided by the Locust test or Python defaults.
--loglevel, -L LOCUST_LOGLEVEL loglevel Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL. Default is INFO.
--logfile LOCUST_LOGFILE logfile Path to log file. If not set, log will go to stdout/stderr
--step-load LOCUST_STEP_LOAD step-load Enable Step Load mode to monitor how performance metrics varies when user load increases. Requires –step-users and –step-time to be specified.
--step-users LOCUST_STEP_USERS step-users User count to increase by step in Step Load mode. Only used together with –step-load
--step-time LOCUST_STEP_TIME step-time Step duration in Step Load mode, e.g. (300s, 20m, 3h, 1h30m, etc.). Only used together with –step-load
--exit-code-on-error LOCUST_EXIT_CODE_ON_ERROR exit-code-on-error Sets the process exit code to use when a test result contain any failure or error
-s, --stop-timeout LOCUST_STOP_TIMEOUT stop-timeout Number of seconds to wait for a simulated user to complete any executing task before exiting. Default is to terminate immediately. This parameter only needs to be specified for the master process when running Locust distributed.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,324评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,303评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,192评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,555评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,569评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,566评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,927评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,583评论 0 257
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,827评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,590评论 2 320
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,669评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,365评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,941评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,928评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,159评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,880评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,399评论 2 342

推荐阅读更多精彩内容