High-performance monitoring and optimization toolkit for trading applications
Project description
Tradata Performance Package
High-performance monitoring and optimization toolkit for trading applications. Provides comprehensive performance monitoring, metrics collection, health checking, and HTTP optimization capabilities.
๐ Features
Performance Monitoring
- Real-time monitoring of API performance, response times, and throughput
- Cache performance tracking with hit/miss rates and efficiency metrics
- System health monitoring with comprehensive health checks
- Performance alerts and threshold monitoring
Metrics Collection
- Request/response metrics with detailed breakdowns
- Custom business metrics collection and aggregation
- Performance counters and call tracking
- Time-series metrics with statistical analysis
FastAPI Middleware
- Performance monitoring middleware for automatic request tracking
- Cache monitoring middleware for cache performance insights
- Request timing middleware with detailed timing headers
- Performance headers middleware for client-side monitoring
HTTP Optimization
- High-performance HTTP client with connection pooling
- Request optimization and performance tuning
- Automatic metrics collection for external API calls
- Connection management and error handling
Decorators & Utilities
- Performance decorators for automatic timing and profiling
- Metrics decorators for custom data collection
- Business metrics decorators for domain-specific monitoring
- Performance profiling with memory and CPU tracking
๐ฆ Installation
Basic Installation
pip install tradata-perf
Development Installation
pip install tradata-perf[dev]
Advanced Features
pip install tradata-perf[advanced]
๐ฏ Quick Start
Basic Performance Monitoring
from tradata_perf import PerformanceMonitoringMiddleware, get_performance_monitor
from fastapi import FastAPI
app = FastAPI()
# Add performance monitoring middleware
app.add_middleware(PerformanceMonitoringMiddleware)
# Get performance monitor instance
monitor = get_performance_monitor()
@app.on_event("startup")
async def startup():
# Monitor is automatically initialized
pass
@app.get("/performance")
async def get_performance():
# Get comprehensive performance summary
summary = monitor.get_performance_summary()
return summary
Using Performance Decorators
from tradata_perf.decorators import timing, profile, monitor_performance
@timing
def slow_function():
time.sleep(1)
return "Done"
@profile(track_memory=True, track_cpu=True)
def memory_intensive_function():
# Function automatically profiled
return "Profiled"
@monitor_performance(threshold_ms=1000)
def critical_function():
# Warning logged if execution exceeds 1 second
return "Monitored"
Custom Metrics Collection
from tradata_perf.decorators import collect_metrics, business_metrics
from tradata_perf import get_metrics_collector
@collect_metrics(metric_type="histogram", tags={"service": "quotes"})
def process_quotes(symbols):
# Metrics automatically collected
return len(symbols)
@business_metrics(
metric_name="quotes_processed",
value_extractor=lambda result: len(result),
tags={"service": "quotes"}
)
def get_quotes(symbols):
# Business metrics automatically collected
return ["AAPL", "TSLA", "GOOGL"]
# Manual metrics collection
collector = get_metrics_collector()
await collector.collect_custom_metric(
name="custom_metric",
value=42.0,
tags={"category": "example"},
metadata={"description": "Custom metric example"}
)
HTTP Client Optimization
from tradata_perf import get_http_client
# Get optimized HTTP client
http_client = get_http_client()
# Make optimized requests
response = await http_client.get("https://api.example.com/data")
# Get performance statistics
stats = http_client.get_performance_stats()
print(f"Success rate: {stats['success_rate_percent']}%")
๐๏ธ Architecture
Core Components
tradata_perf/
โโโ monitoring/ # Performance monitoring core
โ โโโ performance_monitor.py # Main monitoring system
โ โโโ metrics_collector.py # Metrics collection
โ โโโ health_checker.py # Health monitoring
โโโ middleware/ # FastAPI middleware
โ โโโ performance.py # Performance tracking
โ โโโ cache.py # Cache monitoring
โโโ http/ # HTTP optimization
โ โโโ optimized_client.py # High-performance client
โโโ decorators/ # Performance decorators
โ โโโ performance.py # Timing & profiling
โ โโโ metrics.py # Metrics collection
โโโ utils/ # Utility functions
โโโ timing.py # Timing utilities
โโโ profiling.py # Profiling tools
Data Flow
- Request Processing: Middleware automatically captures request metrics
- Performance Tracking: Decorators measure function execution times
- Metrics Collection: Centralized metrics collection and aggregation
- Health Monitoring: Continuous health checks and status reporting
- Performance Analysis: Real-time performance insights and alerts
๐ Performance Metrics
System Metrics
- Total requests and success rates
- Average, P95, and P99 response times
- Requests per minute and throughput
- Error rates and failure analysis
Cache Metrics
- Cache hit/miss rates by endpoint
- Cache operation durations
- Memory usage and eviction rates
- Cache health status
Custom Metrics
- Business-specific metrics
- Performance counters
- Custom aggregations
- Time-series analysis
๐ง Configuration
Environment Variables
# Performance monitoring
PERF_MONITORING_ENABLED=true
PERF_METRICS_INTERVAL=60
PERF_HEALTH_CHECK_INTERVAL=30
# HTTP client
PERF_HTTP_POOL_SIZE=100
PERF_HTTP_TIMEOUT=10.0
# Metrics collection
PERF_MAX_METRIC_SERIES=1000
PERF_METRICS_RETENTION_HOURS=24
Configuration Classes
from tradata_perf.config import PerformanceConfig
config = PerformanceConfig(
monitoring_enabled=True,
metrics_interval=60,
health_check_interval=30,
http_pool_size=100,
enable_profiling=False
)
๐งช Testing
Run Tests
# Basic tests
pytest
# With coverage
pytest --cov=tradata_perf
# Performance benchmarks
pytest --benchmark-only
Test Coverage
- Unit tests for all components
- Integration tests for middleware
- Performance benchmarks for critical paths
- Async testing for all async components
๐ Performance Characteristics
Overhead
- Middleware overhead: < 1ms per request
- Memory footprint: < 50MB baseline
- CPU overhead: < 2% under normal load
- Metrics collection: Non-blocking, async-first design
Scalability
- High-throughput: Supports 10,000+ requests/second
- Memory efficient: Automatic cleanup of old metrics
- Horizontal scaling: Stateless design for microservices
- Resource optimization: Minimal impact on application performance
๐ Use Cases
Trading Applications
- Real-time performance monitoring of trading algorithms
- API latency tracking for market data providers
- Cache performance optimization for quote data
- Health monitoring of critical trading services
Microservices
- Distributed performance monitoring across services
- Service health tracking and alerting
- Performance correlation between services
- Resource utilization monitoring
High-Frequency Systems
- Ultra-low latency monitoring with minimal overhead
- Real-time performance alerts for SLA violations
- Performance profiling of critical code paths
- Throughput optimization and bottleneck identification
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
git clone https://github.com/tradata/tradata-perf-py.git
cd tradata-perf-py
pip install -e .[dev]
pytest
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Support
- Documentation: Full API Documentation
- Examples: Usage Examples
- Issues: GitHub Issues
- Discussions: GitHub Discussions
๐ Related Projects
- tradata-core-py: Core logging and tracing framework
- tradata-utils-py: Utility and infrastructure components
Built with โค๏ธ by the Tradata Team
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tradata_perf-0.2.0.tar.gz.
File metadata
- Download URL: tradata_perf-0.2.0.tar.gz
- Upload date:
- Size: 33.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b1c01e5c259a1ff548e9ddf4cc3c86e6f534cbc8bc99bc66c1202ae329b906b
|
|
| MD5 |
ed5997bc5b57d5c55be5c99764dd54fc
|
|
| BLAKE2b-256 |
1e7c2b5f9d98f0e368ee51484ef239b22ceaee879c9a8d90dd969270e4074b18
|
File details
Details for the file tradata_perf-0.2.0-py3-none-any.whl.
File metadata
- Download URL: tradata_perf-0.2.0-py3-none-any.whl
- Upload date:
- Size: 32.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5faff1e5e2b18ca425b92fec961fff06071a032db6737b6937a9f518d225da9b
|
|
| MD5 |
eb8f7e975847b26c4473238879ff82af
|
|
| BLAKE2b-256 |
a7ae9c51c2360d1d14092a44c314bfcc45f1175f4e983056e384683bde92d759
|