File tree Expand file tree Collapse file tree 5 files changed +55
-0
lines changed
Expand file tree Collapse file tree 5 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 11Locust
22=
3+
4+
5+ ### 1.安装
6+ ``` bash
7+ # so easy
8+ pip install locust
9+ locust -V
10+ ```
11+
12+ ### 2.准备工作
13+ 测试脚本 locust_file.py
14+ ``` python
15+ from locust import HttpUser, task, between
16+
17+ class MyUser (HttpUser ):
18+ # 每个虚拟用户请求之间的等待时间(秒)
19+ wait_time = between(1 , 5 )
20+
21+ @task
22+ def get_index (self ):
23+ self .client.get(" /" )
24+
25+ @task
26+ def get_users (self ):
27+ self .client.get(" /api/users" )
28+ ```
29+ 脚本说明
30+ * HttpUser:基于 HTTP 协议的用户模拟类
31+ * task:定义一个测试任务(可以有多个)
32+ * between(1, 5):每次请求之间随机等待 1~ 5 秒
33+
34+ ### 3.测试服务启动
35+ ``` bash
36+ # 文件路径(locust_file.py)和host替换为真实的
37+ locust -f locust_file.py --host http://127.0.0.1:5000
38+ ```
39+
40+ ### 4.Web UI开始测试
41+ 进入 Web UI 后:
42+ 1 . 输入要模拟的 用户数(Number of users to simulate)
43+ 2 . 输入 启动速率(Spawn rate,多少用户/秒)
44+ 3 . 填写 目标 host(如果命令行没指定的话)
45+ 4 . 点击 Start Swarming 开始压测
46+
47+ ![ before.png] ( before.png )
48+
49+ Web 界面能实时看到:
50+ * 请求总数
51+ * RPS(Requests per second)
52+ * 响应时间曲线
53+ * 错误率
54+
55+ ![ img.png] ( img.png )
56+ ![ img_1.png] ( img_1.png )
57+ ![ img_2.png] ( img_2.png )
You can’t perform that action at this time.
0 commit comments