Locust 安装
Posted klvchen
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Locust 安装相关的知识,希望对你有一定的参考价值。
环境:CentOS 7.4,python2.7.5
# 安装 pip
yum -y install python-pip
# 安装 locustio
pip install locustio
mkdir scripts ;cd scripts/
vi locust_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
# 启动
locust -f locust_test.py --host=https://www.baidu.com
locust post 登录
vi locust_login.py
from locust import HttpLocust, TaskSet, task
import json
class UserBehavior(TaskSet):
def on_start(self):
self.login()
@task(1)
def login(self):
request_url = "/app/user/login"
request_json = {"reqBody":{"account":"xxxx","loginType":1,"password":"xxxxxxxx","openId":"","shareUid":""}}
response = self.client.post(request_url, json=request_json)
if response.status_code != 200:
print "error"
print "response status code:", response.status_code
elif response.status_code == 200:
print "ok"
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 1000
max_wait = 1000
locust -f locust_login.py --host=https://www.xxx.com
以上是关于Locust 安装的主要内容,如果未能解决你的问题,请参考以下文章