Skip to main content

Latency Tracking

Implement comprehensive performance monitoring to track, analyse, and optimise latency across your PraisonAI applications.

Overview

Latency tracking in PraisonAI enables:
  • Phase-specific performance monitoring
  • Request-level metrics collection
  • Thread-safe concurrent tracking
  • Integration with monitoring systems
  • Performance optimisation insights

Basic Latency Tracking

Using the Latency Tracker Tool

Direct Phase Tracking

Advanced Tracking Patterns

Context Manager Pattern

Decorator Pattern

Agent Wrapper Pattern

MCP Server Integration

Tracking MCP Requests

Metrics Analysis

Statistical Analysis

Trend Detection

Integration with Monitoring Systems

Prometheus Integration

CloudWatch Integration

Performance Optimisation

Identifying Bottlenecks

Caching Strategy

Best Practices

1. Granular Tracking

2. Conditional Tracking

3. Sampling

Common Patterns

Request Tracing

Performance Budgets

Troubleshooting

High Latency Issues

  1. Check phase breakdown to identify slow components
  2. Look for outliers that skew averages
  3. Monitor trends to detect degradation
  4. Review concurrent request handling

Memory Leaks

  1. Limit metric history size
  2. Implement cleanup for old metrics
  3. Use weak references where appropriate

Threading Issues

  1. Use thread-safe data structures
  2. Implement proper locking for shared state
  3. Test with concurrent workloads