#
# 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
I have the above locust file. When I run this file using
locust -f mylocustfile.py
and access localhost:8089
And set the
`Number of users to simulate -> 1`
`Hatch rate (users spawned/second) -> 1`
and start the test. The number of requests keep increasing at the rate of 2 per second
I would have expected the maximum requests to be only 1, since both the total number of users and hatch rate is set to 1. Am I missing something?