Locust學習筆記8——命令行參數詳解

  引言

  前面在Locust學習筆記7——no-web模式運行腳本這篇文章中已經講過非GUI模式運行腳本,也就是在windows系統下以命令的方式去運行腳本。而Linux系統也是使用no-web方式運行。所以,我們要了解哪些命令。

  命令行參數

  最簡單的方式,輸入cmd,再dos窗口下輸入locust --help,查看所有的命令行參數

locust --help
usage: locust [-h] [-H HOST] [--web-host WEB_HOST] [-P PORT] [-f LOCUSTFILE]
              [--csv CSVFILEBASE] [--csv-full-history] [--master] [--slave]
              [--master-host MASTER_HOST] [--master-port MASTER_PORT]
              [--master-bind-host MASTER_BIND_HOST]
              [--master-bind-port MASTER_BIND_PORT]
              [--heartbeat-liveness HEARTBEAT_LIVENESS]
              [--heartbeat-interval HEARTBEAT_INTERVAL]
              [--expect-slaves EXPECT_SLAVES] [--no-web] [-c NUM_CLIENTS]
              [-r HATCH_RATE] [-t RUN_TIME] [--skip-log-setup] [--step-load]
              [--step-clients STEP_CLIENTS] [--step-time STEP_TIME]
              [--loglevel LOGLEVEL] [--logfile LOGFILE] [--print-stats]
              [--only-summary] [--no-reset-stats] [--reset-stats] [-l]
              [--show-task-ratio] [--show-task-ratio-json] [-V]
              [--exit-code-on-error EXIT_CODE_ON_ERROR] [-s STOP_TIMEOUT]
              [LocustClass [LocustClass ...]]

Args that start with '--' (eg. -H) can also be set in a config file
(~/.locust.conf or locust.conf). Config file syntax allows: key=value,
flag=true, stuff=[a,b,c] (for details, see syntax at https://goo.gl/R74nmi).
If an arg is specified in more than one place, then commandline values
override config file values which override defaults.

positional arguments:
  LocustClass

optional arguments:
  -h, --help            show this help message and exit
  -H HOST, --host HOST  Host to load test in the following format:
                        http://10.21.32.33
  --web-host WEB_HOST   Host to bind the web interface to. Defaults to '' (all
                        interfaces)
  -P PORT, --port PORT, --web-port PORT
                        Port on which to run web host
  -f LOCUSTFILE, --locustfile LOCUSTFILE
                        Python module file to import, e.g. '../other.py'.
                        Default: locustfile
  --csv CSVFILEBASE, --csv-base-name CSVFILEBASE
                        Store current request stats to files in CSV format.
  --csv-full-history    Store each stats entry in CSV format to
                        _stats_history.csv file
  --master              Set locust to run in distributed mode with this
                        process as master
  --slave               Set locust to run in distributed mode with this
                        process as slave
  --master-host MASTER_HOST
                        Host or IP address of locust master for distributed
                        load testing. Only used when running with --slave.
                        Defaults to 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 --slave. Defaults to 5557.
  --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 MASTER_BIND_PORT
                        Port that locust master should bind to. Only used when
                        running with --master. Defaults to 5557.
  --heartbeat-liveness HEARTBEAT_LIVENESS
                        set number of seconds before failed heartbeat from
                        slave
  --heartbeat-interval HEARTBEAT_INTERVAL
                        set number of seconds delay between slave heartbeats
                        to master
  --expect-slaves EXPECT_SLAVES
                        How many slaves master should expect to connect before
                        starting the test (only when --no-web used).
  --no-web              Disable the web interface, and instead start running
                        the test immediately. Requires -c and -t to be
                        specified.
  -c NUM_CLIENTS, --clients NUM_CLIENTS
                        Number of concurrent Locust users. Only used together
                        with --no-web
  -r HATCH_RATE, --hatch-rate HATCH_RATE
                        The rate per second in which clients are spawned. Only
                        used together with --no-web
  -t RUN_TIME, --run-time RUN_TIME
                        Stop after the specified amount of time, e.g. (300s,
                        20m, 3h, 1h30m, etc.). Only used together with --no-
                        web
  --skip-log-setup      Disable Locust's logging setup. Instead, the
                        configuration is provided by the Locust test or Python
                        defaults.
  --step-load           Enable Step Load mode to monitor how performance
                        metrics varies when user load increases. Requires
                        --step-clients and --step-time to be specified.
  --step-clients STEP_CLIENTS
                        Client count to increase by step in Step Load mode.
                        Only used together with --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
  --loglevel LOGLEVEL, -L LOGLEVEL
                        Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL.
                        Default is INFO.
  --logfile LOGFILE     Path to log file. If not set, log will go to
                        stdout/stderr
  --print-stats         Print stats in the console
  --only-summary        Only print the summary stats
  --no-reset-stats      [DEPRECATED] Do not reset statistics once hatching has
                        been completed. This is now the default behavior. See
                        --reset-stats to disable
  --reset-stats         Reset statistics once hatching has been completed.
                        Should be set on both master and slaves when running
                        in distributed mode
  -l, --list            Show list of possible locust classes and exit
  --show-task-ratio     print table of the locust classes' task execution
                        ratio
  --show-task-ratio-json
                        print json data of the locust classes' task execution
                        ratio
  -V, --version         show program's version number and exit
  --exit-code-on-error EXIT_CODE_ON_ERROR
                        sets the exit code to post on 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.

  你也可以在pycharm編輯器終端terminal輸入:locust --help

  參數中文說明

參數名稱參數值參數說明
-h, --help 不帶參數 查看幫助信息
-H HOST, –host=HOST HOST 指定被測試的主機,採用以格式:http://10.21.32.33
–web-host=WEB_HOST WEB_HOST 指定運行 Locust Web 頁面的主機,默認爲空 “。
-P PORT, –port=PORT, –web-port=PORT PORT 指定 –web-host 的端口,默認是8089
-f LOCUSTFILE, –locustfile=LOCUSTFILE LOCUSTFILE 指定運行 Locust 性能測試文件,默認爲: locustfile.py
–csv=CSVFILEBASE, –csv-base-name=CSVFILEBASE CSVFILEBASE 以CSV格式存儲當前請求測試數據。
–master 不帶參數 Locust 分佈式模式使用,當前節點爲 master 節點。
–slave 不帶參數 Locust 分佈式模式使用,當前節點爲 slave 節點。
–master-host=MASTER_HOST MASTER_HOST 分佈式模式運行,設置 master 節點的主機或 IP 地址,只在與 –slave 節點一起運行時使用,默認爲:127.0.0.1.
–master-port=MASTER_PORT MASTER_PORT 分佈式模式運行, 設置 master 節點的端口號,只在與 –slave 節點一起運行時使用,默認爲:5557。注意,slave 節點也將連接到這個端口+1 上的 master 節點。
–master-bind-host=MASTER_BIND_HOST MASTER_BIND_HOST 做分佈式壓測時,指定分機IP。只用於master。如果沒有指定,默認是所有可用的IP(即所有標記主機IP的slave)
–master-bind-port=MASTER_BIND_PORT MASTER_BIND_PORT 做分佈式壓測時,指定分機port。默認是5557與5558。
–no-web no-web -c 和 -r 配合 模式運行測試,需要 -c 和 -r 配合使用.
-c NUM_CLIENTS, –clients=NUM_CLIENTS NUM_CLIENTS 指定併發用戶數,作用於 –no-web 模式。
-r HATCH_RATE, –hatch-rate=HATCH_RATE HATCH_RATE 指定每秒啓動的用戶數,作用於 –no-web 模式。
-t RUN_TIME, –run-time=RUN_TIME RUN_TIME 設置運行時間, 例如: (300s, 20m, 3h, 1h30m). 作用於 –no-web 模式。
-L LOGLEVEL, –loglevel=LOGLEVEL LOGLEVEL 選擇 log 級別(DEBUG/INFO/WARNING/ERROR/CRITICAL). 默認是 INFO.
–logfile=LOGFILE LOGFILE 日誌文件路徑。如果沒有設置,日誌將去 stdout/stderr
–print-stats 不帶參數 在控制檯中打印數據
–only-summary 不帶參數 只打印摘要統計
–no-reset-stats 不帶參數 Do not reset statistics once hatching has been completed。
-l, –list 不帶參數 顯示測試類, 配置 -f 參數使用
–show-task-ratio 不帶參數 打印 locust 測試類的任務執行比例,配合 -f 參數使用.
–show-task-ratio-json 不帶參數 以 json 格式打印 locust 測試類的任務執行比例,配合 -f 參數使用.
-V, –version 不帶參數 查看當前 Locust 工具的版本.

 

  總結

  前面講案例的時候也講過命令詳情,這裏單獨拎出來講一下常用的一些命令,方便以後查閱。另外,對測試及測試開發感興趣的,有思想的小夥伴們可以加入QQ羣,一起學習與溝通。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章