Locust是一个易于使用,可编写脚本且可扩展的性能测试工具。使用Python代码定义用户行为,并让数百万同时用户拥护您的系统。
文档:https://docs.locust.io/en/stable/
代码:https://github.com/locustio/locust
-
在代码中定义用户行为
不需要笨拙的UI或庞大的XML。只是普通的代码。
-
分布式和可扩展
Locust支持分布在多台计算机上的运行负载测试,因此可用于模拟数百万个同时用户
-
经过验证和战斗力测试
Locust已被用来模拟数百万个并发用户。Battlelog是《战地风云》游戏的网络应用程序,已使用Locust进行了负载测试,因此可以说Locust经过了Battletested;)
安装
PyPI使用pip命令。
> pip install locust
范例程式码
Locust的基本功能是用Python代码描述所有测试。不需要笨拙的UI或庞大的XML,只需简单的代码即可。locustfile.py
from locust import HttpUser, between, task
class WebsiteUser(HttpUser):
wait_time = between(5, 15)
def on_start(self):
self.client.post("/login", {
"username": "test_user",
"password": ""
})
@task
def index(self):
self.client.get("/")
self.client.get("/static/assets.js")
@task
def about(self):
self.client.get("/about/")