The Feed Processing System includes an advanced performance optimization system that automatically tunes processing parameters based on system load and performance metrics. This guide explains how the optimization system works and how to configure it for your needs.
The optimization system dynamically adjusts processing parameters to maintain optimal performance while preventing system overload. It monitors:
- CPU usage and load
- Memory utilization
- I/O wait times
- Processing throughput
- Error rates
Based on these metrics, it automatically adjusts:
- Batch processing sizes
- Number of processing threads
- Processing intervals
- Automatically adjusts batch sizes based on system performance
- Prevents memory overload during high-volume periods
- Increases throughput during low-load periods
- Configurable minimum and maximum bounds
- Dynamically adjusts thread count based on:
- CPU utilization
- I/O wait times
- Processing queue size
- Prevents thread starvation and oversubscription
- Optimizes for both CPU-bound and I/O-bound workloads
- Real-time metrics collection
- Grafana dashboard integration
- Historical performance tracking
- Trend analysis for optimization decisions
from feed_processor.config.processor_config import ProcessorConfig
config = ProcessorConfig(
# Enable/disable dynamic optimization
enable_dynamic_optimization=True,
# Base processing parameters
batch_size=100,
min_batch_size=10,
max_batch_size=500,
# Thread pool configuration
concurrent_processors=4,
min_processors=2,
max_processors=16,
# Performance targets
target_cpu_usage=70.0
)For more fine-grained control, you can adjust these additional parameters:
config = ProcessorConfig(
# Processing timeouts
processing_timeout=300, # seconds
# Polling intervals
poll_interval=60, # seconds
# Metrics configuration
metrics_port=8000
)-
Batch Processing Metrics
feed_processor_batch_size: Current batch sizefeed_processor_items_processed_total: Total processed itemsfeed_processor_processing_duration_seconds: Processing time histogram
-
Thread Pool Metrics
feed_processor_thread_count: Active processing threadsfeed_processor_thread_busy_ratio: Thread utilization
-
System Load Metrics
- CPU usage
- Memory utilization
- I/O wait times
The system includes a pre-configured Grafana dashboard at monitoring/dashboards/optimization.json with panels for:
- Processing batch size trends
- Thread count monitoring
- Item processing rate
- Average processing time
-
Initial Configuration
- Start with default settings
- Monitor system performance for 24-48 hours
- Adjust bounds based on observed patterns
-
Resource Planning
- Allow 30% CPU headroom for spikes
- Monitor memory usage trends
- Consider I/O patterns in thread configuration
-
Monitoring
- Regular review of performance metrics
- Set up alerts for sustained high resource usage
- Track error rates relative to optimization changes
-
High Memory Usage
- Decrease
max_batch_size - Increase processing frequency
- Check for memory leaks
- Decrease
-
Processing Delays
- Increase
min_batch_size - Adjust
target_cpu_usage - Check I/O bottlenecks
- Increase
-
Error Rate Spikes
- Review error patterns
- Adjust retry policies
- Check external service health
-
CPU-Bound Workloads
config = ProcessorConfig( target_cpu_usage=60.0, max_processors=cpu_count, batch_size=100 )
-
I/O-Bound Workloads
config = ProcessorConfig( target_cpu_usage=80.0, max_processors=cpu_count * 2, batch_size=200 )
-
Memory-Constrained Systems
config = ProcessorConfig( max_batch_size=100, max_processors=4, poll_interval=120 )
The system uses a multi-factor optimization approach:
-
Batch Size Calculation
optimal_size = current_size * cpu_factor * error_factor * throughput_trend
-
Thread Count Optimization
optimal_threads = max(1, min(cpu_count * thread_factor, cpu_count * 2))
-
Performance Metrics
throughput = items_processed / processing_time error_rate = items_failed / items_processed
The optimization system is implemented in three main components:
PerformanceOptimizer: Handles metric collection and parameter calculationProcessorConfig: Stores configuration and boundsFeedProcessor: Integrates optimization into processing workflow
For more details, see the source code:
feed_processor/core/optimization.pyfeed_processor/core/processor.pyfeed_processor/config/processor_config.py