py版本的压测:
locust安装:
pip install locustio
示例代码:
import time
from locust import HttpUser, task, between
class QuickstartUser(HttpUser):
wait_time = between(1, 2.5)
@task
def hello_world(self):
self.client.get("/hello")
self.client.get("/world")
@task(3)
def view_items(self):
for item_id in range(10):
self.client.get(f"/item?id={item_id}", name="/item")
time.sleep(1)
def on_start(self):
self.client.post("/login", json={"username":"foo", "password":"bar"})
1. 运行两种方法
a. 终端当前目录运行:locust
b. locust -f locustfile.py ,locust -f +脚本路径
2. 浏览器打开 http://localhost:8089/ 即可使用