Locust installation tips

What 1.Locust that?

An open source load testing tool. python version

2. Install

pip3 install locust

Or Mac installed

brew install libev

 

3. Quick Start

 

locustdemo.py

from locust import HttpLocust, TaskSet, between

def login(l):
    l.client.post("/login", {"username":"ellen_key", "password":"education"})

def logout(l):
    l.client.post("/logout", {"username":"ellen_key", "password":"education"})

def index(l):
    l.client.get("/")

def profile(l):
    l.client.get("/profile")

class UserBehavior(TaskSet):
    tasks = {index: 2, profile: 1}

    def on_start(self):
        login(self)

    def on_stop(self):
        logout(self)

class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    wait_time = between(5.0, 9.0)

4. Run effect

 

Published 301 original articles · won praise 16 · views 30000 +

Guess you like

Origin blog.csdn.net/keny88888/article/details/105308262