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

                                                                                      

 

 

性能测试参数

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值