Locust安装及实战

[root@localhost fx]#  wget https://bootstrap.pypa.io/get-pip.py

[root@localhost fx]# python get-pip.py

[root@localhost fx]# pip install locust

说明:安装中出现安装失败的话,可以使用

sudo pip install --ignore-installed urllib3  把需要的包先安装上。

[root@localhost fx]#

[root@localhost fx]# cat load_test.py

from locust import HttpLocust,TaskSet,task

 

class UserBehavior(TaskSet):

         @task

         def baidu_index(self):

                  self.client.get("/")

class WebsiteUser(HttpLocust):

         task_set = UserBehavior

         min_wait = 3000

         max_wait = 6000

 

[root@localhost fx]# locust -f ./load_test.py --host=https://www.baidu.com

[2017-11-29 15:29:14,258] localhost.localdomain/INFO/locust.main: Starting web monitor at *:8089

[2017-11-29 15:29:14,258] localhost.localdomain/INFO/locust.main: Starting Locust 0.8

Locust安装及实战_第1张图片

Locust安装及实战_第2张图片

                                                                                      

 

 

性能测试参数

Type: 请求的类型,例如GET/POST。

Name:请求的路径。这里为百度首页,即:https://www.baidu.com/

request:当前请求的数量。

fails:当前请求失败的数量。

Median:中间值,单位毫秒,一半的服务器响应时间低于该值,而另一半高于该值。

Average:平均值,单位毫秒,所有请求的平均响应时间。

Min:请求的最小服务器响应时间,单位毫秒。

Max:请求的最大服务器响应时间,单位毫秒。

Content Size:单个请求的大小,单位字节。

reqs/sec:是每秒钟请求的个数。

 

 

locust -f load_test.py --host=https://www.baidu.com --no-web -c 10 -r 2 -t 1m

-f 跟文件名

--host 跟请求地址

–no-web 表示不使用Web界面运行测试。

-c 设置虚拟用户数。

-r 设置每秒启动虚拟用户数。

-t 设置设置运行时间。

 

[root@localhost fx]# locust -h

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

你可能感兴趣的:(性能测试,Locust)