Locust 官方文檔 4:配置運(yùn)行選項(xiàng)

Command Line Options

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

配置 Locust 運(yùn)行方式的最直接方法是通過(guò)命令行參數(shù):

$ 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: 指定測(cè)試系統(tǒng)的 host
                        http://10.21.32.33
  -u NUM_USERS, --users NUM_USERS 測(cè)試的虛擬用戶數(shù),僅與 `--headless` 參數(shù)一起使用
                        Number of concurrent Locust users. Only used together
                        with --headless
  -r HATCH_RATE, --hatch-rate HATCH_RATE  每秒產(chǎn)生用戶的速率,僅與 `--headless` 參數(shù)一起使用
                        The rate per second in which users are spawned. Only
                        used together with --headless
  -t RUN_TIME, --run-time RUN_TIME  在指定時(shí)間后停止測(cè)試,例如 (300s,
                        20m, 3h, 1h30m, etc.),僅與 `--headless` 參數(shù)一起使用
                        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,默認(rèn)使用 `*`(所有界面)
  --web-port WEB_PORT, -P WEB_PORT  Web 界面的運(yùn)行端口
                        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 界面,然后立即開(kāi)始負(fù)載測(cè)試。需要指定 -u 和 -t。
  --web-auth WEB_AUTH   Turn on Basic Auth for the web interface. Should be
                        supplied in the following format: username:password
                        給 Web 界面設(shè)置 Basic Auth。必須提供:username:password。
                        設(shè)置后,打開(kāi) Locust 的 web 界面必須要輸入賬號(hào)密碼
  --tls-cert TLS_CERT   Optional path to TLS certificate to use to serve over
                        HTTPS
                        對(duì)于使用 HTTPS 的服務(wù),提供服務(wù)的 TLS 證書的路徑
  --tls-key TLS_KEY     Optional path to TLS private key to use to serve over
                        HTTPS
                        對(duì)于使用 HTTPS 的服務(wù),提供服務(wù)的 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.
  運(yùn)行 Locust 分布式時(shí)運(yùn)行 Locust Master節(jié)點(diǎn)的選項(xiàng)。主節(jié)點(diǎn)需要連接到它的輔助節(jié)點(diǎn),然后它才能運(yùn)行負(fù)載測(cè)試。

  --master              Set locust to run in distributed mode with this
                        process as master
                        設(shè)置 Locust 運(yùn)行時(shí)的主節(jié)點(diǎn)
  --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 主節(jié)點(diǎn)的接口(host,IP)。僅在與 --master 一起運(yùn)行時(shí)使用。
                        默認(rèn)為 *。
  --master-bind-port MASTER_BIND_PORT
                        Port that locust master should bind to. Only used when
                        running with --master. Defaults to 5557.
                        Locust 主節(jié)點(diǎn)的端口,默認(rèn)使用 5557,僅在與 --master 一起運(yùn)行時(shí)使用
  --expect-workers EXPECT_WORKERS
                        How many workers master should expect to connect
                        before starting the test (only when --headless used).
                        在測(cè)試之前指定擁有多少個(gè)工作節(jié)點(diǎn)。(僅在與 --master 一起運(yùn)行時(shí)使用)

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.
  運(yùn)行 Locust 分布式運(yùn)行的工作節(jié)點(diǎn)選項(xiàng)。
  啟動(dòng)工作節(jié)點(diǎn)時(shí),僅需要指定 locustfile(-f 選項(xiàng)),因?yàn)樵谄渌x項(xiàng)(例如-u,-r,-t)是通過(guò)主節(jié)點(diǎn)指定。

  --worker              Set locust to run in distributed mode with this
                        process as worker
                        在 Locust 分布式運(yùn)行時(shí),使用此參數(shù)指定當(dāng)前 PC 為工作節(jié)點(diǎn)
  --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 分布式執(zhí)行的主節(jié)點(diǎn)地址。僅當(dāng)與 --worker 參數(shù)同時(shí)運(yùn)行時(shí)有效。
                        默認(rèn)為 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 分布式運(yùn)行時(shí)的主節(jié)點(diǎn)端口,僅在與 --worker 同時(shí)運(yùn)行時(shí)有效。
                        默認(rèn)為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 裝飾器對(duì) Locust 任務(wù)進(jìn)行標(biāo)記。這些選項(xiàng)使您可以指定在測(cè)試期間要包括或排除的任務(wù)。

  -T [TAG [TAG ...]], --tags [TAG [TAG ...]]
                        List of tags to include in the test, so only tasks
                        with any matching tags will be executed
                        要包含在測(cè)試中的標(biāo)簽列表,只有被包含的標(biāo)簽標(biāo)記的任務(wù)才會(huì)被執(zhí)行
  -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
                        要排除的標(biāo)簽列表,被指定的標(biāo)簽標(biāo)記的任務(wù)在測(cè)試中不會(huì)被執(zhí)行

Request statistics options:
請(qǐng)求統(tǒng)計(jì)信息選項(xiàng):
  --csv CSV_PREFIX      Store current request stats to files in CSV format.
                        Setting this option will generate three files:
                        將當(dāng)前統(tǒng)計(jì)信息存儲(chǔ)在 CSV 文件中,使用此選項(xiàng)會(huì)生成以下三個(gè)文件:
                        [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
                        將每個(gè)統(tǒng)計(jì)信息條目以 CSV 格式存儲(chǔ)到 _stats_history.csv
  --print-stats         Print stats in the console  將統(tǒng)計(jì)信息打印到控制臺(tái)
  --only-summary        Only print the summary stats  僅打印統(tǒng)計(jì)信息
  --reset-stats         Reset statistics once hatching has been completed.
                        Should be set on both master and workers when running
                        in distributed mode
                        測(cè)試完成后重置統(tǒng)計(jì)信息。在分布式模式下應(yīng)同時(shí)設(shè)置主節(jié)點(diǎn)和工作節(jié)點(diǎn)

Logging options:
日志選項(xiàng):
  --skip-log-setup      Disable Locust's logging setup. Instead, the
                        configuration is provided by the Locust test or Python
                        defaults.
                        禁用 Locust 日志。相反,配置由 Locust 測(cè)試或 Python 提供默認(rèn)值。
  --loglevel LOGLEVEL, -L LOGLEVEL
                        Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL.
                        Default is INFO.
                        選擇日志級(jí)別,默認(rèn)為 INFO
  --logfile LOGFILE     Path to log file. If not set, log will go to
                        stdout/stderr
                        指定存放日志的文件路徑。如果不設(shè),日志僅顯示在標(biāo)準(zhǔn)輸出/標(biāo)準(zhǔn)錯(cuò)誤

Step load options:
Step 加載選項(xiàng):
  --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.
                        啟用逐步加載模式以監(jiān)視性能指標(biāo)隨著用戶負(fù)載的增加而變化。
                        需要同時(shí)指定 --step-users 和 --step-time。
  --step-users STEP_USERS
                        User count to increase by step in Step Load mode. Only
                        used together with --step-load
                        在逐步加載模式下,每步增加的用戶數(shù)量。僅與 --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
                        逐步加載模式下,每步持續(xù)時(shí)間,例如(300s,20m,3h,1h30m等)。
                        僅與--step-load一起使用

Other options:
其他選項(xiàng):
  --show-task-ratio     Print table of the User classes' task execution ratio. 打印 User 類的任務(wù)執(zhí)行率
  --show-task-ratio-json
                        Print json data of the User classes' task execution
                        ratio
                        打印 User 類的任務(wù)執(zhí)行率的 json 數(shù)據(jù)
  --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
                        當(dāng)測(cè)試結(jié)果包含失敗或錯(cuò)誤時(shí),設(shè)置程序的退出碼
  -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.
                       虛擬用戶在執(zhí)行完成后退出等待的時(shí)間。默認(rèn)為立即停止。
                       分布式執(zhí)行時(shí),只需要在主進(jìn)程中指定即可。
                       
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)

環(huán)境變量

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

可以通過(guò)命令行參數(shù)設(shè)置的大多數(shù)選項(xiàng)也可以通過(guò)環(huán)境變量設(shè)置。例如:

配置文件

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.

可以通過(guò)命令行配置各項(xiàng)參數(shù),也可以使用配置文件 config file 進(jìn)行配置。

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

Locust 默認(rèn)會(huì)查找 ~/.locust.conf./locust.conf 作為配置文件,也可以使用 --config 參數(shù)指定文件。

Example:

$ locust --config=master.conf

Note

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

注意:配置值會(huì)按如下順序讀取

所有有效的配置項(xiàng)

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

下表列出了所有可用的配置選項(xiàng)及其對(duì)應(yīng)的環(huán)境和配置文件鍵值:

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.
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容