$ show locustio/locust
Locust is an open-source, developer-friendly load testing framework written in Python. It allows users to define test scenarios as regular Python code using `User` classes with `@task` decorators and configurable wait times. The system supports HTTP and other protocols via built-in clients (HttpUser, FastHttpUser) and extensible contrib modules (MQTT, gRPC, Postgres, etc.). It provides a real-time web UI built with React/Redux/MUI for controlling tests and viewing statistics, a headless CLI mode for CI/CD integration, and a distributed architecture using ZMQ for master/worker coordination. The framework collects detailed per-request metrics (response times, percentiles, error rates) and can export CSV, HTML, and JSON reports. It also integrates with OpenTelemetry for observability. The codebase is well-structured with a clean event-driven architecture, extensive test coverage, and a plugin system for custom extensions.
The LLM identified 6 files worth highlighting for reuse:
Implements a generic EventHook class that allows registering listeners and firing events with optional context manager for measuring execution time. Used throughout Locust for lifecycle hooks (test_start, test_stop, request, etc.). The implementation is clean, type-safe, and reusable in any Python project needing a simple event system.
Provides a `memoize` decorator with configurable timeout (in seconds). Uses functools.lru_cache internally but adds expiration logic. The implementation is concise, thread-safe (via time checks), and can be extracted for use in any Python project requiring time-based caching of function results.
Offers a `retry` decorator that retries a function on specified exceptions with configurable delays (constant, exponential backoff, or jitter). The implementation is self-contained, well-documented, and demonstrates a robust retry pattern suitable for network calls or flaky operations.
Contains pure functions for generating user think times: `between`, `constant`, `constant_pacing`, `constant_throughput`, and `poisson`. Each function returns a callable that yields a random wait time according to the specified distribution. These are simple, well-tested, and reusable in any simulation or scheduling context.
Provides generic array utility functions such as `updateArraysAtProps` (immutable update of nested array properties) and `shallowMerge`. These are pure TypeScript functions with unit tests, demonstrating a pattern for safe state updates in React/Redux applications. Reusable in any frontend project.
Contains functions for converting object keys between camelCase and snake_case (`camelCaseKeys`, `snakeCaseKeys`). These are pure, well-tested utilities that solve a common data transformation problem when interfacing between JavaScript and Python backends. Reusable in any TypeScript project.