讀前參考:《性能測試工具Locust 》html
熟悉 Apache ab 工具的同窗都知道,它是沒有界面的,經過命令行執行。 Locust 一樣也提供的命令行運行,好處就是更節省客戶端資源。node
以上一節的 baidu 首頁測試(load_test.py)爲例 經過 no-web 模式運行測試。web
> locust -f load_test.py --host=https://www.baidu.com --no-web -c 10 -r 2 -t 1m
[2017-10-30 22:17:30,292] DESKTOP-SMGQBBM/INFO/locust.main: Run time limit set to 60 seconds
[2017-10-30 22:17:30,302] DESKTOP-SMGQBBM/INFO/locust.main: Starting Locust 0.8
[2017-10-30 22:17:30,302] DESKTOP-SMGQBBM/INFO/locust.runners: Hatching and swarming 10 clients at the rate 2 clients/s...
Name # reqs # fails Avg Min Max | Median req/s
....
[2017-10-30 22:18:30,301] DESKTOP-SMGQBBM/INFO/locust.main: Time limit reached. Stopping Locust.
[2017-10-30 22:18:30,302] DESKTOP-SMGQBBM/INFO/locust.main: Shutting down (exit code 0), bye.
Name # reqs # fails Avg Min Max | Median req/s
--------------------------------------------------------------------------------------------------------------------------------------------
GET / 117 0(0.00%) 31 17 96 | 28 2.10
--------------------------------------------------------------------------------------------------------------------------------------------
Total 117 0(0.00%) 2.10
Percentage of the requests completed within given times
Name # reqs 50% 66% 75% 80% 90% 95% 98% 99% 100%
--------------------------------------------------------------------------------------------------------------------------------------------
GET / 117 28 30 36 37 49 62 69 72 96
--------------------------------------------------------------------------------------------------------------------------------------------
Total 117 28 30 36 37 49 62 69 72 96
啓動參數:json
–no-web 表示不使用Web界面運行測試。併發
-c 設置虛擬用戶數。分佈式
-r 設置每秒啓動虛擬用戶數。工具
-t 設置設置運行時間。post
打開命令提示符(或Linux終端),輸入 locust --help
。性能
> locust --help
Usage: locust [options] [LocustClass [LocustClass2 ... ]]
Options:
-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.
--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. Note that
slaves will also connect to the master node on this
port + 1.
--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. Note that
Locust will also use this port + 1, so by default the
master node will bind to 5557 and 5558.
--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 -r 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
-L LOGLEVEL, --loglevel=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 Do not reset statistics once hatching has been
completed
-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
參數說明:測試
參數 | 說明 |
---|---|
-h, –help | 查看幫助 |
-H HOST, –host=HOST | 指定被測試的主機,採用以格式:http://10.21.32.33 |
–web-host=WEB_HOST | 指定運行 Locust Web 頁面的主機,默認爲空 「。 |
-P PORT, –port=PORT, –web-port=PORT | 指定 –web-host 的端口,默認是8089 |
-f LOCUSTFILE, –locustfile=LOCUSTFILE | 指定運行 Locust 性能測試文件,默認爲: locustfile.py |
–csv=CSVFILEBASE, –csv-base-name=CSVFILEBASE | 以CSV格式存儲當前請求測試數據。 |
–master | Locust 分佈式模式使用,當前節點爲 master 節點。 |
–slave | Locust 分佈式模式使用,當前節點爲 slave 節點。 |
–master-host=MASTER_HOST | 分佈式模式運行,設置 master 節點的主機或 IP 地址,只在與 –slave 節點一塊兒運行時使用,默認爲:127.0.0.1. |
–master-port=MASTER_PORT | 分佈式模式運行, 設置 master 節點的端口號,只在與 –slave 節點一塊兒運行時使用,默認爲:5557。注意,slave 節點也將鏈接到這個端口+1 上的 master 節點。 |
–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. Note that Locust will also use this port + 1, so by default the master node will bind to 5557 and 5558. |
–expect-slaves=EXPECT_SLAVES | How many slaves master should expect to connect before starting the test (only when –no-web used). |
–no-web | no-web 模式運行測試,須要 -c 和 -r 配合使用. |
-c NUM_CLIENTS, –clients=NUM_CLIENTS | 指定併發用戶數,做用於 –no-web 模式。 |
-r HATCH_RATE, –hatch-rate=HATCH_RATE | 指定每秒啓動的用戶數,做用於 –no-web 模式。 |
-t RUN_TIME, –run-time=RUN_TIME | 設置運行時間, 例如: (300s, 20m, 3h, 1h30m). 做用於 –no-web 模式。 |
-L LOGLEVEL, –loglevel=LOGLEVEL | 選擇 log 級別(DEBUG/INFO/WARNING/ERROR/CRITICAL). 默認是 INFO. |
–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 工具的版本. |
個別參數,我沒用過,也太清楚其含義,暫時就不翻譯了。