#
# 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。我错过了什么吗?