|
1 | 1 | # Tiled Load Testing with Locust
|
2 | 2 |
|
3 |
| -Simple load testing for Tiled using the `reader.py` file. |
| 3 | +Load testing for Tiled using Locust. Two test files are available: |
| 4 | +- `reader.py` - Tests HTTP read operations and search endpoints |
| 5 | +- `streaming.py` - Tests streaming data writes and WebSocket delivery latency |
4 | 6 |
|
5 | 7 | ## Quick Start
|
6 | 8 |
|
7 | 9 | ```bash
|
8 |
| -# Install dependencies (dev environment includes locust) |
9 |
| -pixi install -e dev |
| 10 | +# Install dependencies (locust should already be available in the environment) |
| 11 | +# If not installed, add it to your requirements or install with: |
| 12 | +# uv add locust |
10 | 13 | ```
|
11 | 14 |
|
| 15 | +## Starting Test Server |
| 16 | + |
| 17 | +Before running locust tests, start a Tiled server: |
| 18 | + |
| 19 | +```bash |
| 20 | +# Basic server (works for most tests) |
| 21 | +uv run tiled serve catalog \ |
| 22 | + --host 0.0.0.0 \ |
| 23 | + --port 8000 \ |
| 24 | + --api-key secret \ |
| 25 | + --temp \ |
| 26 | + --init |
| 27 | +``` |
| 28 | + |
| 29 | +For streaming tests with Redis cache (optional): |
| 30 | +```bash |
| 31 | +# Start Redis first |
| 32 | +redis-server |
| 33 | + |
| 34 | +# Start Tiled server with Redis cache |
| 35 | +uv run tiled serve catalog \ |
| 36 | + --host 0.0.0.0 \ |
| 37 | + --port 8000 \ |
| 38 | + --api-key secret \ |
| 39 | + --cache "redis://localhost:6379" \ |
| 40 | + --cache-ttl 60 \ |
| 41 | + --temp \ |
| 42 | + --init |
| 43 | +``` |
| 44 | + |
| 45 | +This creates a temporary catalog with: |
| 46 | +- API key authentication (key: "secret") |
| 47 | +- Temporary writable storage (automatically cleaned up) |
| 48 | +- Optional Redis cache for enhanced streaming performance |
| 49 | +- Server running on http://localhost:8000 |
| 50 | + |
| 51 | +## Reading Performance Tests (`reader.py`) |
| 52 | + |
| 53 | +Tests various HTTP endpoints for reading data, metadata, and search operations. |
| 54 | + |
12 | 55 | ### Examples
|
13 | 56 | Run with default localhost server (uses default API key 'secret'):
|
14 | 57 | ```bash
|
15 |
| -pixi run -e dev locust -f reader.py --host http://localhost:8000 |
| 58 | +uv run locust -f reader.py --headless -u 100 -r 10 -t 60s --host http://localhost:8000 |
16 | 59 | ```
|
17 | 60 |
|
18 | 61 | Run with custom API key:
|
19 | 62 | ```bash
|
20 |
| -pixi run -e dev locust -f reader.py --host http://localhost:8000 --api-key your-api-key |
| 63 | +uv run locust -f reader.py --headless -u 100 -r 10 -t 60s --host http://localhost:8000 --api-key your-api-key |
21 | 64 | ```
|
22 | 65 |
|
23 | 66 | Run with custom container name (defaults to locust_testing):
|
24 | 67 | ```bash
|
25 |
| -pixi run -e dev locust -f reader.py --host http://localhost:8000 --container-name my_test_container |
| 68 | +uv run locust -f reader.py --headless -u 100 -r 10 -t 60s --host http://localhost:8000 --container-name my_test_container |
| 69 | +``` |
| 70 | + |
| 71 | +## Streaming Performance Tests (`streaming.py`) |
| 72 | + |
| 73 | +Tests streaming data writes and WebSocket delivery with end-to-end latency measurement. |
| 74 | + |
| 75 | +**Note:** The `--node-name` parameter is required for streaming tests to avoid conflicts when multiple test runs create nodes with the same name. |
| 76 | + |
| 77 | +### Examples |
| 78 | +Run with required node name: |
| 79 | +```bash |
| 80 | +uv run locust -f streaming.py --headless -u 10 -r 2 -t 120s --host http://localhost:8000 --node-name my_test_stream |
26 | 81 | ```
|
27 | 82 |
|
28 |
| -## Headless Mode |
29 |
| -Run without the web interface: |
| 83 | +Run with custom API key: |
30 | 84 | ```bash
|
31 |
| -pixi run -e dev locust -f reader.py --headless -u 100 -r 10 -t 60s |
| 85 | +uv run locust -f streaming.py --headless -u 10 -r 2 -t 120s --host http://localhost:8000 --api-key your-api-key --node-name my_test_stream |
32 | 86 | ```
|
33 |
| -- `-u 100`: 100 concurrent users |
34 |
| -- `-r 10`: Spawn 10 users per second |
35 |
| -- `-t 60s`: Run for 60 seconds |
| 87 | + |
| 88 | +Control user types with environment variables: |
| 89 | +```bash |
| 90 | +# 2 writers for every 1 streaming reader |
| 91 | +WRITER_WEIGHT=2 STREAMING_WEIGHT=1 uv run locust -f streaming.py --headless -u 10 -r 2 -t 120s --host http://localhost:8000 --node-name my_test_stream |
| 92 | +``` |
| 93 | + |
| 94 | +### Streaming Test Components |
| 95 | +- **WriterUser**: Writes timestamped array data to streaming nodes |
| 96 | +- **StreamingUser**: Connects via WebSocket to measure write-to-delivery latency |
| 97 | + |
| 98 | +## Parameters |
| 99 | +- `-u N`: N concurrent users |
| 100 | +- `-r N`: Spawn N users per second |
| 101 | +- `-t Ns`: Run for N seconds |
| 102 | +- `--headless`: Run without web interface (required for automation) |
| 103 | + |
| 104 | +## Notes |
| 105 | +- All examples use `--headless` mode for reliable automation |
| 106 | +- For streaming tests, `--node-name` is required to avoid conflicts |
| 107 | +- Use environment variables `WRITER_WEIGHT` and `STREAMING_WEIGHT` to control user distribution |
0 commit comments