Conversational BI Performance Optimization Guide
Conversational BI Performance Optimization Guide
Version: 7.0
Table of Contents
- Overview
- Performance Targets
- Quick Start - Top 10 Optimizations
- Latency Optimization
- Memory Optimization
- Throughput Optimization
- Cache Optimization
- Database Optimization
- LLM Integration Optimization
- Monitoring & Profiling
- Production Tuning
- Troubleshooting
Overview
This guide provides comprehensive performance optimization strategies for HeliosDB Conversational BI in production environments.
Performance Philosophy
Goal: Sub-200ms P99 latency for 95%+ accurate NL2SQL translation
Approach:
- Optimize the critical path (query → SQL generation)
- Minimize LLM calls through aggressive caching
- Reduce memory allocation overhead
- Maximize throughput through concurrency
Performance Targets
Latency Targets
# Target latencies (P99)session_creation: <10mscache_lookup: <5msschema_loading: <20msllm_call: <200ms # External dependencysql_generation_total: <200mscontext_tracking: <10msresponse_formatting: <5msMemory Targets
# Memory usage per componentsession_state: <500KBconversation_context: <1MBschema_cache: <5MB per databasesemantic_cache: <100MB totaltotal_per_session: <2MBThroughput Targets
# Concurrent requestssingle_instance: 150+ QPSwith_caching: 500+ QPScluster: 1000+ QPSQuick Start - Top 10 Optimizations
1. Enable Semantic Caching
Impact: 70-80% latency reduction for similar queries
[cache]enabled = truemax_entries = 10000ttl_seconds = 3600similarity_threshold = 0.85Why: Avoids expensive LLM calls for semantically similar queries.
2. Optimize Connection Pooling
Impact: 40-50% latency reduction for database operations
[database]pool_size = 20 # 2x CPU coresmax_connections = 100connection_timeout_ms = 5000idle_timeout_seconds = 300Why: Eliminates connection establishment overhead.
3. Configure Rate Limiting
Impact: Prevents overload, ensures consistent performance
[rate_limiting]enabled = truequeries_per_minute = 60 # Per tenantburst_allowance = 10Why: Protects against traffic spikes and ensures fair resource allocation.
4. Enable Circuit Breakers
Impact: Graceful degradation, prevents cascade failures
[circuit_breaker]enabled = truefailure_threshold = 5reset_timeout_seconds = 60half_open_requests = 3Why: Isolates failures and prevents system-wide outages.
5. Optimize Context Window
Impact: 20-30% memory reduction
[context]max_turns = 10 # Down from 20max_context_length = 2000 # Down from 4000context_compression = trueWhy: Reduces memory footprint and LLM token usage.
6. Configure Aggressive Timeouts
Impact: Prevents slow queries from blocking resources
[timeouts]llm_timeout_ms = 5000 # 5 secondssql_execution_timeout_ms = 10000 # 10 secondstotal_request_timeout_ms = 15000 # 15 secondsWhy: Ensures predictable latency and resource release.
7. Enable Request Batching
Impact: 2-3x throughput improvement
[batching]enabled = truemax_batch_size = 10batch_timeout_ms = 100Why: Amortizes LLM call overhead across multiple requests.
8. Optimize Schema Caching
Impact: 50-60% reduction in schema loading time
[schema_cache]enabled = truemax_schemas = 100preload_popular = trueeviction_policy = "LRU"Why: Eliminates repeated schema extraction overhead.
9. Configure LLM Model Routing
Impact: 30-40% cost and latency reduction
[llm]fast_model = "gpt-3.5-turbo" # Simple queriesaccurate_model = "gpt-4" # Complex queriescomplexity_threshold = 0.7Why: Uses cheaper/faster models when appropriate.
10. Enable Parallel Processing
Impact: 2x throughput improvement
[concurrency]max_concurrent_requests = 50worker_threads = 8 # CPU coresasync_processing = trueWhy: Maximizes resource utilization and throughput.
Latency Optimization
Critical Path Analysis
Total Latency = Cache + Schema + LLM + Tracking + Formatting ~200ms = 5ms + 20ms + 150ms + 10ms + 5msOptimization Priority:
- LLM call (150ms) - Cache aggressively
- Schema loading (20ms) - Preload and cache
- Context tracking (10ms) - Optimize data structures
- Cache lookup (5ms) - Use in-memory hash maps
- Response formatting (5ms) - Minimize serialization
Memory Optimization
Memory Allocation Strategy
Goal: <2MB per session
Breakdown:
Session State: 500KB (25%)Context History: 800KB (40%)Schema Cache: 400KB (20%)Temp Buffers: 300KB (15%)-----------------------------------Total: 2000KB (100%)Throughput Optimization
Concurrency Configuration
Optimal Settings (8-core system):
[concurrency]worker_threads = 8 # Match CPU coresmax_concurrent_requests = 50 # 5-10x workerstask_queue_size = 200 # 4x concurrent requestsCache Optimization
Semantic Cache Strategy
Configuration:
[semantic_cache]enabled = truemax_entries = 10000ttl_seconds = 3600similarity_threshold = 0.85embedding_model = "text-embedding-ada-002"Hit Rate Target: >90% for production workloads
Database Optimization
Connection Pool Tuning
Optimal Configuration:
[database.pool]min_connections = 5max_connections = 20 # 2x CPU coresconnection_timeout = 5000idle_timeout = 300max_lifetime = 1800LLM Integration Optimization
Model Selection
Decision Tree:
Query Complexity < 0.7 → gpt-3.5-turbo (fast, cheap)Query Complexity ≥ 0.7 → gpt-4 (accurate, slower)Has cache hit → Skip LLM entirelyMonitoring & Profiling
Key Metrics to Track
Latency Metrics:
# P50, P90, P95, P99histogram_quantile(0.99, rate(query_duration_seconds_bucket[5m]))
# By componenthistogram_quantile(0.99, rate(llm_call_duration_seconds_bucket[5m]))histogram_quantile(0.99, rate(cache_lookup_duration_seconds_bucket[5m]))Throughput Metrics:
# Queries per secondrate(queries_total[1m])
# Cache hit raterate(cache_hits_total[5m]) / rate(cache_requests_total[5m])Resource Metrics:
# Memory usageprocess_resident_memory_bytes
# CPU usagerate(process_cpu_seconds_total[1m])Production Tuning
Recommended Production Configuration
# Production-optimized configuration
[general]environment = "production"log_level = "info"
[cache]enabled = truemax_entries = 50000 # Increased for productionttl_seconds = 7200 # 2 hourssimilarity_threshold = 0.85
[database]pool_size = 20max_connections = 100connection_timeout_ms = 5000
[rate_limiting]enabled = truequeries_per_minute = 100 # Adjusted per SLAburst_allowance = 20
[circuit_breaker]enabled = truefailure_threshold = 5reset_timeout_seconds = 60
[concurrency]worker_threads = 16 # Production servermax_concurrent_requests = 100
[timeouts]llm_timeout_ms = 5000total_request_timeout_ms = 15000
[monitoring]metrics_enabled = truemetrics_port = 9090tracing_enabled = trueScaling Strategies
Vertical Scaling (Single Instance):
- 16+ CPU cores
- 32+ GB RAM
- SSD storage
- Expected: 150-200 QPS
Horizontal Scaling (Cluster):
- Load balancer (session affinity)
- 3+ instances
- Shared cache (Redis)
- Expected: 500+ QPS
Auto-Scaling Rules:
scale_up: - cpu_usage > 70% for 5 minutes - p99_latency > 300ms for 5 minutes - queue_depth > 100
scale_down: - cpu_usage < 30% for 15 minutes - queue_depth < 20Troubleshooting
High Latency
Symptom: P99 > 500ms
Diagnosis:
# Check cache hit ratecurl http://localhost:9090/metrics | grep cache_hit_rate
# Check LLM latencycurl http://localhost:9090/metrics | grep llm_durationSolutions:
- Increase cache size → Improve hit rate
- Enable semantic caching → Reduce LLM calls
- Use faster LLM model → Reduce LLM latency
- Add more workers → Increase concurrency
High Memory Usage
Symptom: Memory > 4GB per instance
Diagnosis:
# Check cache sizecurl http://localhost:9090/metrics | grep cache_size_bytesSolutions:
- Reduce cache size → Lower memory footprint
- Enable context compression → Smaller sessions
- Reduce max_turns → Less history
- Implement aggressive eviction → Free memory
Low Throughput
Symptom: QPS < 50
Diagnosis:
# Check queue depthcurl http://localhost:9090/metrics | grep queue_depth
# Check worker utilizationcurl http://localhost:9090/metrics | grep worker_busy_ratioSolutions:
- Increase worker_threads → More parallelism
- Increase max_concurrent_requests → Higher queue
- Optimize database pool → Reduce contention
- Enable request batching → Better efficiency
Cache Misses
Symptom: Hit rate < 50%
Diagnosis:
# Analyze cache patternscurl http://localhost:9090/metrics | grep cache_
# Check similarity thresholdgrep similarity_threshold config.tomlSolutions:
- Lower similarity_threshold → More liberal matching
- Improve query normalization → Better key generation
- Preload common queries → Warm cache
- Increase cache TTL → Longer retention
Performance Checklist
Pre-Production
- Run load tests (100+ concurrent users)
- Profile CPU and memory usage
- Execute BIRD benchmark subset
- Validate cache hit rate (>70%)
- Test circuit breaker activation
- Verify rate limiting enforcement
- Check monitoring and alerting
- Review timeout configuration
Post-Deployment
- Monitor P99 latency (<200ms target)
- Track cache hit rate (>90% target)
- Watch memory usage (<2MB per session)
- Measure throughput (>150 QPS)
- Collect user feedback
- Analyze query patterns
- Optimize based on production data
- Plan capacity scaling
Conclusion
Performance optimization is an ongoing process. Use this guide as a reference for:
- Initial Configuration - Start with recommended settings
- Production Monitoring - Track key metrics continuously
- Iterative Tuning - Adjust based on real workload
- Problem Solving - Use troubleshooting section for issues
Key Takeaways
Cache Aggressively - 70-80% latency reduction Optimize Critical Path - Focus on LLM and schema loading Monitor Continuously - Metrics drive optimization Scale Appropriately - Vertical first, horizontal for growth Test Thoroughly - Load test before production
Target Summary
| Metric | Target | Optimization |
|---|---|---|
| P99 Latency | <200ms | Cache + Fast Models |
| Memory | <2MB | Compression + Eviction |
| Throughput | 150+ QPS | Concurrency + Batching |
| Cache Hit | >90% | Semantic + Preload |
With these optimizations, HeliosDB Conversational BI can meet the targets above at scale.
Version: 7.0