Overview
Latency optimization ensures the early warning system responds quickly to critical patient conditions. The platform automatically adjusts batch sizes based on hardware constraints to minimize detection latency while maximizing throughput.Measuring Latency
Per-Row Latency
Track processing time per data row:real_time/streaming.py:27
Detection Latency
Measure time from event occurrence to alert:- Time in seconds from first event to first alert
infif no alerts after eventnanif no events in ground truth
anomaly_detection/early_warning.py:17-26
Hardware-Aware Optimization
Auto-Adjusting Batch Size
The system automatically adjusts batch size based on hardware constraints:evaluation/early_warning_experiment.py:30
Hardware Profiles
Define resource constraints:- Adjust batch sizes dynamically
- Prevent memory overflow
- Balance latency vs throughput
- Maximize resource utilization
Latency Under Constraints
Running Constrained Experiments
evaluation/early_warning_experiment.py:23-61
Understanding Results
Key metrics from constraint experiments:Latency vs Accuracy Tradeoff
The experiment generates visualizations:evaluation/early_warning_experiment.py:79-88
Resource Score Analysis
Calculate resource score to understand performance:evaluation/early_warning_experiment.py:91-99
First Alert Latency
Track time to first critical alert:anomaly_detection/early_warning.py:7-14
Optimization Strategies
1. Tune Chunk Size
2. Hardware-Aware Processing
evaluation/early_warning_experiment.py:46
3. Stream Interval Tuning
Adjust how frequently new data arrives:- Low interval (10-50ms): Real-time monitoring, high load
- Medium interval (100-200ms): Balanced performance
- High interval (500ms+): Reduced load, acceptable for non-critical monitoring
Best Practices
- Start with chunk_size=100 and adjust based on
latency_msmetrics - Use
auto_adjust_batch_size()for hardware-constrained environments - Monitor
detection_latency_sfor critical conditions (target <5s) - Balance
detection_qualitywithcompute_utilization - Test under realistic constraints before deployment
- Use streaming for latency-critical applications
- Plot latency vs accuracy to find optimal operating point
- Track false positive rate to avoid alert fatigue
- Set stream_interval based on data arrival rate