- Definition: Load testing is a type of performance testing that simulates real-world user traffic to evaluate how a system behaves under expected and peak load conditions. It helps determine if the application meets performance goals.
- Primary objective: Verify that the system can handle the anticipated number of concurrent users while maintaining acceptable response times and error rates. This validates infrastructure capacity and application stability.
- Key concepts: Virtual users represent simulated human actions. Think time mimics user pauses between interactions. Ramp-up gradually increases load to observe system scaling behavior.
- Importance: Performance failures can cause revenue loss, customer churn, and brand reputation damage. Load testing identifies bottlenecks before production release, reducing incident risk.
- Common misconceptions: Load testing is not the same as functional testing; it targets system limits, not correctness. It requires realistic workload models, not just single-user scripts.
- When to perform: Early in development (shift-left) to catch regressions, before major releases, and after infrastructure changes or feature additions. Continuous load testing is a recommended practice.
- Outcomes: Key deliverables include performance baselines, bottleneck identification, capacity limits, and recommendations for optimization. These inform capacity planning and scaling decisions.
- Role in SDLC: Load testing integrates with CI/CD pipelines to provide rapid feedback. It supports performance engineering by enabling teams to evaluate trade-offs between cost and performance.
- Types of load tests: Stress testing pushes beyond normal limits to find breaking points. Spike testing applies sudden, massive load surges to verify recovery. Endurance testing runs over extended periods to detect memory leaks or degradation under sustained use.
- Critical metrics to monitor: Response time percentiles (p50, p95, p99) reveal user experience distribution. Throughput measures requests per second handled successfully. Error rate tracks failures like HTTP 500s or timeouts. Correlation with resource utilization pinpoints root causes.
- Realistic workload modeling: Use production traffic patterns, including geographic distribution, user session durations, and data volumes. Incorporate random think times and navigation paths to avoid artificial patterns that mask true system behavior under load.
- Infrastructure considerations: Ensure test environment mirrors production in hardware, network latency, and database size. Monitor both application and underlying system resources such as CPU, memory, disk I/O, and database connection pools to correlate performance degradation with resource constraints.
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(1, 5)
@task
def index_page(self):
self.client.get('/')
@task(3)
def view_item(self):
self.client.get('/item?id=100')This Locust script defines a user that performs two tasks: visiting the index page and viewing an item. The wait_time simulates user think time between 1 and 5 seconds. The @task decorator assigns relative weights; here, view_item is executed three times more often than index_page.
- Load testing simulates real-world traffic to evaluate system behavior under load.
- Primary objectives include verifying performance, scalability, and stability.
- Key concepts include virtual users, think time, and ramp-up.
- Early and continuous load testing helps prevent production failures.