Skip to content

Commit 29bd2f1

Browse files
committed
feat: Add sophisticated rate limiting system for streaming GPS data
- Implement Rate-Limited State Manager pattern for high-frequency telemetry - Add configurable per-aircraft, per-message-type rate limiting (position 500ms, velocity 1s, ID immediate) - Include time-based debouncing to handle rapid update bursts - Provide automatic cleanup and eviction of stale aircraft - Add comprehensive statistics and monitoring via control port - Integrate CLI arguments for rate limit configuration - Maintain backward compatibility with existing tracker functionality - Add 19 comprehensive unit and integration tests - Update documentation with usage examples and architectural details This addresses streaming data applications that need to track item state while discarding frequent, noisy updates and ejecting inactive items.
1 parent ef8f2cd commit 29bd2f1

11 files changed

+1238
-9273
lines changed

CLAUDE.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ cargo run --release
2020

2121
# Run with custom parameters (see listen-adsb binary for all options)
2222
cargo run -- --gain 40.0 --preamble-threshold 12.0
23+
24+
# Run with rate limiting enabled to reduce CPU usage on high-traffic scenarios
25+
cargo run -- --rate-limit
26+
27+
# Run with custom rate limiting intervals
28+
cargo run -- --rate-limit --position-rate-ms 1000 --velocity-rate-ms 2000
2329
```
2430

2531
## Architecture
@@ -29,7 +35,8 @@ cargo run -- --gain 40.0 --preamble-threshold 12.0
2935
- **Preamble Detector** (`src/preamble_detector.rs`): Detects ADS-B message preambles in the signal
3036
- **Demodulator** (`src/demodulator.rs`): Demodulates detected frames into bit streams
3137
- **Decoder** (`src/decoder.rs`): Decodes bit streams into ADS-B packets using the `adsb_deku` library
32-
- **Tracker** (`src/tracker.rs`): Maintains aircraft state and position tracking with optional aircraft lifetime management
38+
- **Tracker** (`src/tracker.rs`): Maintains aircraft state and position tracking with optional aircraft lifetime management and rate limiting
39+
- **Rate Limiter** (`src/rate_limiter.rs`): Provides configurable rate limiting to reduce CPU usage on high-frequency updates
3340

3441
### Signal Processing Flow
3542

@@ -52,9 +59,66 @@ The application uses FutureSDR's flowgraph architecture:
5259

5360
Edit `config.toml` to modify:
5461
- `log_level`: Logging verbosity
55-
- `ctrlport_bind`: Web server bind address and port
62+
- `ctrlport_bind`: Web server bind address and port
5663
- `frontend_path`: Path to web interface files
5764

65+
## Rate Limiting
66+
67+
AirJedi includes sophisticated rate limiting capabilities to reduce CPU usage in high-traffic scenarios where aircraft send frequent, repetitive updates. This is particularly useful for GPS data processing where updates need to be filtered to prevent resource waste.
68+
69+
### Features
70+
71+
- **Per-aircraft rate limiting**: Each aircraft is tracked independently
72+
- **Per-message type limiting**: Different limits for positions, velocities, identification, and metadata
73+
- **Time-based debouncing**: Rapid updates are queued and only the latest is processed
74+
- **Automatic cleanup**: Inactive aircraft are automatically removed from tracking
75+
- **Real-time monitoring**: Statistics and metrics available via control port
76+
77+
### Default Rate Limits
78+
79+
- **Position updates**: 500ms (maximum 2 updates per second)
80+
- **Velocity updates**: 1000ms (maximum 1 update per second)
81+
- **Identification updates**: 0ms (immediate, no rate limiting)
82+
- **Metadata updates**: 5000ms (maximum 1 update per 5 seconds)
83+
84+
### Usage
85+
86+
```bash
87+
# Enable rate limiting with default settings
88+
cargo run -- --rate-limit
89+
90+
# Customize rate limiting intervals (in milliseconds)
91+
cargo run -- --rate-limit \
92+
--position-rate-ms 1000 \
93+
--velocity-rate-ms 2000 \
94+
--identification-rate-ms 0 \
95+
--metadata-rate-ms 10000
96+
97+
# Rate limiting works with all output formats
98+
cargo run -- --rate-limit --beast --raw --sbs1 --websocket
99+
```
100+
101+
### Monitoring
102+
103+
Rate limiting statistics are logged every 30 seconds when enabled:
104+
```
105+
Rate Limiting Stats: 1250 total updates, 65% immediate, 35% rate-limited, 12 active aircraft, 8 pending updates
106+
```
107+
108+
You can also query statistics via the control port:
109+
- Send `"stats"` to get rate limiting statistics in JSON format
110+
- Send `"aircraft"` to get aircraft data (same as before)
111+
112+
### Architecture
113+
114+
The rate limiting system uses a **Rate-Limited State Manager** pattern that combines:
115+
- **State tracking** per aircraft with configurable update intervals
116+
- **Time-based debouncing** to handle rapid update bursts
117+
- **LRU-style cleanup** to prevent memory leaks from inactive aircraft
118+
- **Multi-tier output pipeline** separating immediate broadcasting from state updates
119+
120+
This ensures external consumers (via BEAST, Raw, SBS-1, WebSocket outputs) always receive immediate updates while internal state tracking is intelligently rate-limited.
121+
58122
## Dependencies
59123

60124
- **FutureSDR**: Signal processing framework (version 0.0.38 from crates.io)

0 commit comments

Comments
 (0)