Skip to main content

High-performance monitoring and optimization toolkit for trading applications

Project description

Tradata Performance Package

Python 3.8+ License: MIT Code style: black

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

  1. Request Processing: Middleware automatically captures request metrics
  2. Performance Tracking: Decorators measure function execution times
  3. Metrics Collection: Centralized metrics collection and aggregation
  4. Health Monitoring: Continuous health checks and status reporting
  5. 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

๐Ÿ”— Related Projects


Built with โค๏ธ by the Tradata Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tradata_perf-0.2.1.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tradata_perf-0.2.1-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file tradata_perf-0.2.1.tar.gz.

File metadata

  • Download URL: tradata_perf-0.2.1.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tradata_perf-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9be858293c90c4da17c0bdb66125367610eb59a1f7a8b45a91c492bbc6424405
MD5 b171ad94e9c99866fea8c15f33b98609
BLAKE2b-256 b9db4610b1a1bc246863bdd831f0d81f1df53551650cdcc039212be1d2cb3140

See more details on using hashes here.

File details

Details for the file tradata_perf-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: tradata_perf-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 31.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tradata_perf-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8c6d900b705182257bc53ff027aea9a3dfa2df23d02c34b234b5cb6fe6eb0436
MD5 5bd5651737c7d1c023f92aba9af69592
BLAKE2b-256 6052083dab89205e19a7ad2d8f3f925db2a8f7008e30530fe2e7c59fc43df457

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page