Prompt
Locust autoscaling test
Latest observation
Oct 20, 2026
OpenAI APIWeb search: off
Here’s a practical Locust autoscaling test approach you can use to verify HPA/KEDA/cluster autoscaling behavior.
Goal
Simulate increasing load with Locust and observe:
- application latency / errors
- pod CPU/memory scaling
- autoscaler reaction time
- whether the system stabilizes under peak load
Example test plan
- Start with a small number of users.
- Ramp up traffic gradually.
- Hold peak load long enough to trigger scaling.
- Ramp down and confirm scale-in behavior.
Suggested load profile
- 10 users for 2 minutes
- 50 users for 5 minutes
- 200 users for 10 minutes
- Ramp down to 0–10 users
Example Locust file
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(1, 3)
@task
def homepage(self):
self.client.get("/")
Run Locust
locust -f locustfile.py --host=http://your-service-url
For headless execution:
locust -f locustfile.py --host=http://your-service-url --headless -u 200 -r 20 -t 15m
-u 200= target users-r 20= spawn rate users/sec-t 15m= total duration
Better staged load test
Use a custom load shape:
from locust import HttpUser, task, between, LoadTestShape
class WebsiteUser(HttpUser):
wait_time = between(1, 3)
@task
def homepage(self):
self.client.get("/")
class StagedShape(LoadTestShape):
stages = [
{"duration": 120, "users": 10, "spawn_rate": 5},
{"duration": 420, "users": 50, "spawn_rate": 10},
{"duration": 1020, "users": 200, "spawn_rate": 20},
{"duration": 1320, "users": 20, "spawn_rate": 10},
]
def tick(self):
run_time = self.get_run_time()
for stage in self.stages:
if run_time < stage["duration"]:
return stage["users"], stage["spawn_rate"]
return None
Run:
locust -f locustfile.py --host=http://your-service-url
What to monitor
- Pod replicas over time
- CPU/memory usage
- Request latency p95/p99
- HTTP error rates
- Node autoscaling events
- Ingress / service saturation
- Queue depth if applicable
Useful checks
- Does HPA scale when CPU > target?
- Does the app stay within SLO during scaling delay?
- Are there cold-start issues?
- Does cluster autoscaler add nodes fast enough?
- Does scale-down happen too aggressively?
Tip
If you want to test autoscaling effectively, make sure:
- requests have realistic payloads
- your app has a meaningful CPU/memory load
- Locust workers are scaled separately if needed
- you run the test from outside the cluster or from dedicated load-generator pods
If you want, I can also give you:
- a Kubernetes manifest for running Locust,
- a Locust distributed setup, or
- a Grafana dashboard checklist for autoscaling validation.