使用locust做简单的性能测试

439 阅读1分钟

安装及简单使用

pip install locust -i https://pypi.tuna.tsinghua.edu.cn/simple

使用:

test.py

import time
from locust import HttpUser, task, between

class QuickstartUser(HttpUser):
    wait_time = between(1, 2)

    @task
    def index_page(self):
        self.client.get("http://10.68.178.41:8000/")

运行

locust -f test.py

浏览器访问“localhost:8089”

分布运行

# 主节点
locust -f test.py --master

# 任务节点,“--master-host” 为主节点IP
locust -f test.py --worker --master-host=192.168.100.100

参考文档:

docs.locust.io/en/stable/w…