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
上一篇:C++ 输入、输出运算符重载


下一篇:使用jdom进行xml解析,网络抓包