#
# run command: locust --host=localhost:8000
#
import inspect
import time
from settings import CONFIG
from locust import Locust, TaskSet, task, events
from lib.usermodule import user_create_service
def stopwatch(func):
def wrapper(*args, **kwargs):
# get task's function name
previous_frame = inspect.currentframe().f_back
_, _, task_name, _, _ = inspect.getframeinfo(previous_frame)
start = time.time()
result = None
try:
result = func(*args, **kwargs)
except Exception as e:
total = int((time.time() - start) * 1000)
events.request_failure.fire(request_type="TYPE",
name=task_name,
response_time=total,
exception=e)
else:
total = int((time.time() - start) * 1000)
events.request_success.fire(request_type="TYPE",
name=task_name,
response_time=total,
response_length=0)
return result
return wrapper
class GRPCMyClient:
def __init__(self):
self.usermodule_hostport = CONFIG['grpc']['mymodule_url']
@stopwatch
# this is the method we want to measure
def user_create_service(self, service_name):
user_create_service(service_name)
return True
class GRPCMyLocust(Locust):
def __init__(self):
super(GRPCMyLocust, self).__init__()
self.client = GRPCMyClient()
class GRPCMyTasks(TaskSet):
@task
def user_create_service(self):
self.client.user_create_service("koustubh-api-test")
class GRPCMyUser(GRPCMyLocust):
task_set = GRPCMyTasks
min_wait = 1000
max_wait = 1000
我有上面的蝗虫文件。 当我使用
运行此文件时locust -f mylocustfile.py
并访问localhost:8089
并设置
`Number of users to simulate -> 1`
`Hatch rate (users spawned/second) -> 1`
我希望最大请求数仅为1,因为用户总数和孵化率都设置为1。 我想念什么吗?
答案 0 :(得分:0)
使用Locust Web时,它将继续填充,除非您单击“停止”按钮,而不管指定的#users是什么。为了克服这个问题,有两种选择
self.on_stop()
。OR
蝗虫-f --no-web -c 1000 -r 100-运行时1h30m
蝗虫将在指定的时间后停止