在蝗虫中将用户添加到测试过程的自定义速率
Custom rate for adding user to test process in locust
我对 locust
和负载测试还很陌生,我需要编写一个负载测试,总共应该有 30 个用户,这些用户应该逐步添加到测试中,每分钟 3 个用户,同时有 30 个用户,测试应该是 运行 for 5 minutes.Is 有什么办法可以做到这一点?
对于这个时间,足以添加 LoadTestShape
class 到 locustfile.py
,如下所示:
class StagesShape(LoadTestShape):
"""
A simply load test shape class that has different user and spawn_rate at
different stages.
Keyword arguments:
stages -- A list of dicts, each representing a stage with the following keys:
duration -- When this many seconds pass the test is advanced to the next stage
users -- Total user count
spawn_rate -- Number of users to start/stop per second
stop -- A boolean that can stop that test at a specific stage
stop_at_end -- Can be set to stop once all stages have run.
"""
stages = [
{"duration": 60, "users": 3, "spawn_rate": 0.05},
{"duration": 60, "users": 6, "spawn_rate": 0.05},
{"duration": 60, "users": 9, "spawn_rate": 0.05},
{"duration": 60, "users": 12, "spawn_rate": 0.05},
{"duration": 60, "users": 15, "spawn_rate": 0.05},
{"duration": 60, "users": 18, "spawn_rate": 0.05},
{"duration": 60, "users": 21, "spawn_rate": 0.05},
{"duration": 60, "users": 24, "spawn_rate": 0.05},
{"duration": 60, "users": 27, "spawn_rate": 0.05},
{"duration": 300, "users": 30, "spawn_rate": 0.05},
]
def tick(self):
run_time = self.get_run_time()
for stage in self.stages:
if run_time < stage["duration"]:
tick_data = (stage["users"], stage["spawn_rate"])
return tick_data
return None
我对 locust
和负载测试还很陌生,我需要编写一个负载测试,总共应该有 30 个用户,这些用户应该逐步添加到测试中,每分钟 3 个用户,同时有 30 个用户,测试应该是 运行 for 5 minutes.Is 有什么办法可以做到这一点?
对于这个时间,足以添加 LoadTestShape
class 到 locustfile.py
,如下所示:
class StagesShape(LoadTestShape):
"""
A simply load test shape class that has different user and spawn_rate at
different stages.
Keyword arguments:
stages -- A list of dicts, each representing a stage with the following keys:
duration -- When this many seconds pass the test is advanced to the next stage
users -- Total user count
spawn_rate -- Number of users to start/stop per second
stop -- A boolean that can stop that test at a specific stage
stop_at_end -- Can be set to stop once all stages have run.
"""
stages = [
{"duration": 60, "users": 3, "spawn_rate": 0.05},
{"duration": 60, "users": 6, "spawn_rate": 0.05},
{"duration": 60, "users": 9, "spawn_rate": 0.05},
{"duration": 60, "users": 12, "spawn_rate": 0.05},
{"duration": 60, "users": 15, "spawn_rate": 0.05},
{"duration": 60, "users": 18, "spawn_rate": 0.05},
{"duration": 60, "users": 21, "spawn_rate": 0.05},
{"duration": 60, "users": 24, "spawn_rate": 0.05},
{"duration": 60, "users": 27, "spawn_rate": 0.05},
{"duration": 300, "users": 30, "spawn_rate": 0.05},
]
def tick(self):
run_time = self.get_run_time()
for stage in self.stages:
if run_time < stage["duration"]:
tick_data = (stage["users"], stage["spawn_rate"])
return tick_data
return None