I’m using Locust for stress testing my application API, but I’m experiencing dramatic fluctuations in the Requests Per Second (RPS). for example, The RPS goes up to 2000 and then drops to 2 RPS in 2 seconds, which is not consistent with the expected behavior based on my code. Additionally, I checked the OCI logs and noticed that not all requests are reaching the server as specified in the code, resulting in inconsistent request handling.
Here is my current Locust test script:
class UserBehavior(HttpUser):
host = "https://example.com/api/"
wait_time = between(2, 2)
@task
def one(self):
actions = [
(self.client.post, "createg", {"goal": "New Goal", "amount": random.randint(100, 1000)}),
(self.client.post, "listg"),
]
action = random.choice(actions)
with self.client.request(action[0].__name__.upper(), action[1], json=action[2] if len(action) > 2 else None, catch_response=True) as response:
if response.status_code != 200:
response.failure(f"Failed with status code: {response.status_code}")
@task
def two(self):
actions = [
(self.client.post, "newd", {"amount": random.randint(100, 500)}),
(self.client.post, "listd"),
(self.client.post, "requestd", {"amount": random.randint(50, 200)}),
(self.client.post, "listw")
]
action = random.choice(actions)
with self.client.request(action[0].__name__.upper(), action[1], json=action[2] if len(action) > 2 else None, catch_response=True) as response:
if response.status_code != 200:
response.failure(f"Failed with status code: {response.status_code}")
@task
def three(self):
actions = [
(self.client.post, "v1/tickets/create", {"subject": "Issue", "description": "Description"}),
(self.client.post, "v1/tickets/list"),
(self.client.post, "v1/tickets/reply", {"message": "Reply"})
]
action = random.choice(actions)
with self.client.request(action[0].__name__.upper(), action[1], json=action[2] if len(action) > 2 else None, catch_response=True) as response:
if response.status_code != 200:
response.failure(f"Failed with status code: {response.status_code}")
env = Environment(user_classes=[UserBehavior])
runner = env.create_local_runner()
web_ui = env.create_web_ui("0.0.0.0", 8090)
env.events.init.fire(environment=env, runner=runner, web_ui=web_ui)
gevent.spawn(stats_history, env.runner)
def start_test():
num_users = 20000
spawn_rate = 67
runner.start(user_count=num_users, spawn_rate=spawn_rate)
@events.test_start.add_listener
def on_test_start(environment, **kwargs):
start_test()
gevent.spawn_later(3600, lambda: runner.quit())
runner.greenlet.join()
web_ui.stop()
here is RPS chart from locust
Any insights or suggestions on what might be causing this issue and how to resolve it would be greatly appreciated.
Thank you!
RAN is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.