????????????????????????????????????Locust??
???????
????Locust ?????????????????????? Python ???????????????????????????????
????Locust ???????????????????????????????Locust????????????????????и?????????????????????????????????????
????Locust ???????????????????????????????????????????????????????????????Locust ?????????????????Э????????????gevent??????IO?л?????
???????
????· ???????Python?????д??????????????????κ??????????
????· ????&?????? - ?????????????
????· ????webui???????
????· ?????????????
???????
????pip install locustio
????????
????easy_install locustio
???????????????????????“locust --help”?????
??????????
????????????http://docs.locust.io/en/latest/installation.html
?????????
????test.py
from locust import web?? HttpLocust?? TaskSet?? events??task
import random?? traceback
# ?????μ?web????
@web.app.route("/hi")
def my_added_page():
return "hello locust..."
# ???????
def on_request_success(request_type?? name?? response_time?? response_length):
print 'Type: %s?? Name: %s?? Time: %fms?? Response Length: %d' % \
(request_type?? name?? response_time?? response_length)
def on_request_failure(request_type?? name?? response_time?? exception):
print 'Type: %s?? Name: %s?? Time: %fms?? Reason: %r' % \
(request_type?? name?? response_time?? exception)
events.request_success += on_request_success
events.request_failure += on_request_failure
class UserBehavior(TaskSet):
def on_start(self):
""" on_start is called when a Locust start before any task is scheduled """
self.login()
def login(self):
with self.client.post("/login"?? {"username":"ellen_key"?? "password":"education"}?? catch_response = True) as r:
if random.choice([0?? 1]):
r.success()
else:
r.failure('0')
@task(2)
def index(self):
self.client.get("/")
@task(1)
def profile(self):
self.client.get("/profile")
class WebsiteUser(HttpLocust):
# ??????TaskSet??TaskSet?????????????????
task_set = UserBehavior
# ??????С???min_wait?????????????max_wait
min_wait = 5000
max_wait = 9000
host = http://127.0.0.1
????????
???????????
????locust -f test.py
????webui????????localhost:8089

????ui?????????д??????????
????number of users to simulate??????????????
????Hatch rate (users spawned/second):?????????????????????????????????
????????
????master?????????
????locust -f test.py --master --master-port=8888(??????8080???)
????salve?????????
????locust -f test.py --slave --master-host=<master-IP> --master-bind-host=8888