简介
Locust 是一款易用的,可编程的,可度量的性能测试工具
你可以通过 Python 代码定义 Locust 的 user 行为,而不会受困于UI界面或者限制性的领域特定语言。
这使得 Locust 极具可扩展性,并且对开发者十分友好。
开始使用的第一步,下载 Locust
开始使用
Locust 本质是 Python 程序。这使得 Locust 非常灵活,且能很好地执行复杂的用户流。Locust 也能做一些简单测试,例如:
from locust import HttpUser, task
class HelloWorldUser(HttpUser):
@task
def hello_world(self):
self.client.get("/hello")
self.client.get("/world")
这个 User 会先后对 /hello 和 /world 发起 HTTP 请求 ,并不断循环。更完整的说明,以及获取一些更接近实际应用的例子可以查看:编写 locustfile
把代码放入当前目录的 locustfile.py 文件,并执行 locust
$ locust
[2021-07-24 09:58:46,215] .../INFO/locust.main: Starting web interface at http://*:8089
[2021-07-24 09:58:46,285] .../INFO/locust.main: Starting Locust 2.12.1