Performance Testing Quick Reference¶
๐ Quick Commands¶
Setup¶
Performance Tests¶
Load Testing¶
Benchmarking¶
pytest benchmarks/ --benchmark-only -v
make benchmark # Run benchmarks
make benchmark-save # Save for comparison
Profiling¶
Regression Detection¶
Reports¶
๐ Metrics & Targets¶
| Metric | Target | Test |
|---|---|---|
| P95 Latency (cached) | < 200ms | test_p95_latency_cached_queries |
| P99 Latency (API) | < 500ms | test_api_response_time |
| Cache Hit Rate | > 80% | test_cache_hit_rate |
| Task Completion | > 95% | test_task_completion_rate |
| System Uptime | > 99.5% | test_system_uptime_simulation |
๐ Monitoring Endpoints¶
curl http://localhost:8000/health # Health check
curl http://localhost:8000/metrics # Prometheus metrics
curl http://localhost:8000/api/performance/metrics # Performance summary
curl http://localhost:8000/api/performance/slow-queries # Slow queries
๐งช Test Files¶
tests/performance/
โโโ load_test.py # Locust load tests
โโโ stress_test.py # Stress & endurance tests
โโโ test_targets.py # Performance target validation
โโโ regression_detection.py # Regression detection
โโโ profile.py # Profiling tools
โโโ generate_report.py # Report generation
benchmarks/
โโโ bench_cache.py # Cache benchmarks
โโโ bench_components.py # Component benchmarks
โโโ bench_core.py # Core model benchmarks
โโโ bench_dsl.py # DSL benchmarks
๐ฏ Load Test Traffic Pattern¶
- 80% - Simple price queries (
GET PRICE OF AAPL) - 15% - Deep analysis (narratives, sentiment, fundamentals)
- 5% - FK-DSL queries (
COMPARE AAPL WITH MSFT)
๐ก Common Tasks¶
Run Specific Stress Test¶
pytest tests/performance/stress_test.py::test_peak_load -v
pytest tests/performance/stress_test.py::test_spike_load -v
pytest tests/performance/stress_test.py::test_endurance -v
Run Specific Benchmark¶
pytest benchmarks/bench_components.py::TestCacheBenchmarks --benchmark-only
pytest benchmarks/bench_components.py::TestProviderBenchmarks --benchmark-only
Profile Specific Component¶
python tests/performance/profile.py --target cache --duration 30
python tests/performance/profile.py --target providers --duration 30
Custom Profiling¶
python tests/performance/profile.py --mode cprofile --code "
import asyncio
from fiml.cache.manager import cache_manager
async def test():
await cache_manager.initialize()
# Your code here
await cache_manager.shutdown()
asyncio.run(test())
"
๐ Troubleshooting¶
Server Not Running¶
Redis/PostgreSQL Issues¶
View Slow Queries¶
Check Cache Hit Rate¶
from fiml.monitoring.performance import performance_monitor
metrics = performance_monitor.get_cache_metrics()
print(f"L1 hit rate: {metrics['L1']['hit_rate']:.2%}")
๐ Grafana Setup¶
docker-compose up -d grafana
# Access at http://localhost:3000 (admin/admin)
# Import dashboards from config/grafana/dashboards/
๐ Documentation¶
- Full Guide:
docs/development/PERFORMANCE_TESTING.md - Suite README:
tests/performance/README.md - Implementation Summary:
PERFORMANCE_SUITE_SUMMARY.md - BLUEPRINT Targets:
BLUEPRINT.md(Section 18)
โ ๏ธ CI Integration¶
Performance tests run automatically on: - โ Pull Requests (benchmarks + regression detection) - โ Main branch commits (update baseline) - โ Weekly schedule (full stress tests)
PR will FAIL if: - >10% performance regression detected - Performance targets not met - Error rate exceeds thresholds
๐ฆ Dependencies¶
Main dependencies (included in [performance]): - locust - Load testing - py-spy - Profiling with flame graphs - memory-profiler - Memory analysis - psutil - System metrics - httpx - Async HTTP testing
๐ Best Practices¶
- โ Create baseline before optimization
- โ Test incrementally (start low, increase load)
- โ Profile before optimizing
- โ Monitor in production
- โ Document changes
๐ Support¶
- Check
docs/development/PERFORMANCE_TESTING.md - Review generated reports in
tests/performance/reports/ - Check CI logs for automated tests
- Open issue on GitHub
Version: 1.0
Last Updated: 2025-11-23
Maintained By: FIML Performance Team