locust: Delay at startup and high cpu usage on Windows in Python 3.12
Prerequisites
- I am using the latest version of Locust
- I am reporting a bug, not asking a question
Description
When I start a test with let’s say 50 peak users and a spawn rate of 10, locust won’t run any requests for 5 seconds and the starts them all at once. Same happens when I increase or decrease the peak number while a test is running: The test stops completely
Weird is also, that it complains about high CPU usage, which is not the case at all (CPU is a Ryzen 7 7800X3D).
This issue only happens since I updated locust to the latest version a while ago. Before that the user ramp-up/-down ran butter smooth.
I use locust via the Web UI.
PS C:\Users\kimdr\OneDrive\Dokumente\Git\magicline-webhook-endpoint\app> locust -f .\tests\load_test.py
[2024-01-16 19:59:24,612] Kim-PC-Win-11/INFO/locust.main: Starting web interface at http://localhost:8089 (accepting connections from all network interfaces)
[2024-01-16 19:59:24,620] Kim-PC-Win-11/INFO/locust.main: Starting Locust 2.20.1
[2024-01-16 19:59:34,757] Kim-PC-Win-11/INFO/locust.runners: Ramping to 50 users at a rate of 10.00 per second
[2024-01-16 19:59:40,314] Kim-PC-Win-11/WARNING/root: CPU usage above 90%! This may constrain your throughput and may even give inconsistent response time measurements! See https://docs.locust.io/en/stable/running-distributed.html for how to distribute the load over multiple CPU cores or machines
[2024-01-16 19:59:42,107] Kim-PC-Win-11/INFO/locust.runners: All users spawned: {"WebsiteUser": 50} (50 total users)
[2024-01-16 19:59:43,914] Kim-PC-Win-11/INFO/load_test: Response 200: {'entityId': 1210013898, 'uuid': 'abf6cc05-6ff6-4a95-b846-b2744cd931cf', 'payload': [{'timestamp': 1705431575350, 'type': 'CUSTOMER_CHECKOUT', 'content': None}]}
[2024-01-16 19:59:43,921] Kim-PC-Win-11/INFO/load_test: Response 200: {'entityId': 1210006695, 'uuid': '6c8220fa-15b4-4e42-b650-a07e035689ea', 'payload': [{'timestamp': 1705431574758, 'type': 'CUSTOMER_CHECKOUT', 'content': None}]}
...
This is what it looks like in the UI with the weird startup and rampup (negative spike at the end of the graph)
Command line
locust -f .\tests\load_test.py
Locustfile contents
import logging
from locust import FastHttpUser, TaskSet, task, between
from dependencies import headers, settings
from tests.utils import TestClient
logger = logging.getLogger(__name__)
print("Preparing Test Client...")
test_client = TestClient(
magicline_tenant_name=settings.magicline_tenant_name,
magicline_api_key=settings.magicline_api_key,
is_sandbox=True
)
class PerformanceTest(TaskSet):
def on_start(self):
self.headers = headers
self.client.headers = self.headers
def on_stop(self):
pass # add code that you want to run during ramp down
@task(300)
def test_api_performance(self):
self.client.headers = headers
# Light-weight function that generates fake data using pre-fetched data and the faker package
data = test_client.generate_fake_event()
res = self.client.post("/api/v1/magicline/event", json=data, headers=headers)
logger.info(f"Response {res.status_code}: {data}")
@task(1)
def test_health_check(self):
self.client.get("/api/v1/health", headers=self.headers)
class WebsiteUser(FastHttpUser):
tasks = [PerformanceTest]
network_timeout = 5.0
connection_timeout = 5.0
wait_time = between(0.5, 1)
Python version
3.12
Locust version
2.20.1
Operating system
Windows 11
About this issue
- Original URL
- State: open
- Created 5 months ago
- Comments: 19
The
FastHttpUser
is actually what I’m using already. 😅 Thanks for investigating!For now, you can try using FastHttpUser as a workaround.
wait, now I WAS able to reproduce with https. Probably some exception is being triggered and then there is an infinite loop. I will investigate.