Overview
Duckling is designed for high performance out-of-the-box, but you can optimize for your specific workload using configuration tuning. This guide covers all performance-related settings.Key Performance Factors
Sync Performance
Optimize data replication throughput from MySQL to DuckDB
Query Performance
Maximize analytical query speed on DuckDB
Resource Utilization
Balance CPU, memory, and I/O usage
Concurrency
Handle multiple simultaneous operations
Sync Performance Tuning
Batch Size Configuration
BATCH_SIZE controls how many records are fetched from MySQL per batch:- Higher values (2000-5000): Faster sync, higher memory usage
- Lower values (500-1000): Slower sync, lower memory usage
- Small tables (<100K rows):
BATCH_SIZE=500 - Medium tables (100K-10M rows):
BATCH_SIZE=1000(default) - Large tables (>10M rows):
BATCH_SIZE=2000-5000 - Memory constrained:
BATCH_SIZE=500
Insert Batch Size
INSERT_BATCH_SIZE controls how many records are inserted into DuckDB per batch:- Higher values (3000-5000): Faster inserts, higher memory usage
- Lower values (1000-2000): Slower inserts, lower memory usage
- Default:
INSERT_BATCH_SIZE=2000 - High throughput:
INSERT_BATCH_SIZE=5000 - Memory constrained:
INSERT_BATCH_SIZE=1000
Duckling uses the DuckDB Appender API which achieves 60,000+ rows/sec, 6x faster than traditional INSERT statements.
Appender Flush Interval
APPENDER_FLUSH_INTERVAL controls how often the Appender flushes to disk (milliseconds):- Higher values (10000-30000): Better throughput, higher memory usage
- Lower values (1000-5000): More frequent disk writes, lower memory usage
- Default:
APPENDER_FLUSH_INTERVAL=5000 - High throughput:
APPENDER_FLUSH_INTERVAL=10000 - Low latency:
APPENDER_FLUSH_INTERVAL=1000
Sync Interval
SYNC_INTERVAL_MINUTES controls how often automatic sync runs:- Lower values (5-10): Near real-time sync, higher load
- Higher values (30-60): Lower load, less fresh data
- Real-time analytics:
SYNC_INTERVAL_MINUTES=5 - Standard analytics:
SYNC_INTERVAL_MINUTES=15(default) - Batch analytics:
SYNC_INTERVAL_MINUTES=60
For near real-time sync (<5 minutes), consider enabling CDC (Change Data Capture) instead of polling-based sync.
Connection Pool Tuning
MySQL Connections
MYSQL_MAX_CONNECTIONS sets the MySQL connection pool size:- Higher values (10-20): More parallel table fetches, higher MySQL load
- Lower values (3-5): Less MySQL load, slower sync
- Small databases (<20 tables):
MYSQL_MAX_CONNECTIONS=3 - Medium databases (20-100 tables):
MYSQL_MAX_CONNECTIONS=5(default) - Large databases (>100 tables):
MYSQL_MAX_CONNECTIONS=10 - Shared MySQL: Keep low (3-5) to avoid overwhelming source
DuckDB Connections
DUCKDB_MAX_CONNECTIONS sets the DuckDB connection pool size:- Higher values (20-50): More concurrent queries, higher memory usage
- Lower values (5-10): Less memory usage, query queuing
- Low query volume:
DUCKDB_MAX_CONNECTIONS=10(default) - High query volume:
DUCKDB_MAX_CONNECTIONS=20-30 - Memory constrained:
DUCKDB_MAX_CONNECTIONS=5
Worker Thread Configuration
WORKER_THREADS controls parallel processing threads:0: Auto-detect (recommended)1-N: Explicit thread count
- More threads: Better parallelism for large table syncs
- Fewer threads: Lower CPU usage
- Default:
WORKER_THREADS=0(auto) - CPU constrained:
WORKER_THREADS=2 - High throughput:
WORKER_THREADS=8(match CPU cores)
DuckDB automatically parallelizes queries internally. This setting controls Duckling’s sync operation parallelism.
Query Performance Tuning
Query Governor
MAX_CONCURRENT_QUERIES limits simultaneous query execution:- Higher values: More concurrent queries, higher resource usage
- Lower values: Better per-query performance, query queuing
- Default:
MAX_CONCURRENT_QUERIES=10 - High concurrency:
MAX_CONCURRENT_QUERIES=20 - Resource constrained:
MAX_CONCURRENT_QUERIES=5
Query Timeout
QUERY_TIMEOUT_MS sets maximum query execution time:- Higher values: Allow long-running queries
- Lower values: Prevent runaway queries
- Interactive queries:
QUERY_TIMEOUT_MS=30000(default) - Analytical queries:
QUERY_TIMEOUT_MS=300000(5 minutes) - Report generation:
QUERY_TIMEOUT_MS=600000(10 minutes)
Query Queue
QUERY_QUEUE_MAX sets maximum queued queries:- Higher values: More buffering, higher memory usage
- Lower values: Faster query rejection under load
- Default:
QUERY_QUEUE_MAX=50 - High load:
QUERY_QUEUE_MAX=100 - Fail fast:
QUERY_QUEUE_MAX=20
Memory Management
System Requirements
Minimum:- CPU: 2 cores
- RAM: 2 GB
- Disk: 2x database size
- CPU: 4+ cores
- RAM: 8+ GB
- Disk: 3x database size (for backups)
- CPU: 8+ cores
- RAM: 16+ GB
- Disk: SSD, 3x database size
Memory Usage Patterns
| Operation | Memory Usage | Peak Memory |
|---|---|---|
| Sync (1000 batch) | ~50 MB per table | ~200 MB |
| Sync (5000 batch) | ~250 MB per table | ~1 GB |
| Query (simple) | ~10 MB | ~50 MB |
| Query (complex) | ~100 MB | ~500 MB |
| Backup | ~100 MB | ~500 MB |
| S3 Upload | Streaming | ~100 MB |
DuckDB uses memory-mapped I/O for database files. Ensure sufficient free RAM for the OS to cache frequently accessed data.
Monitoring Memory
Check system metrics:rssMB> 80% of available RAMheapUsedMBgrowing continuously (memory leak)eventLoopLagMs> 100ms (overload)
I/O Optimization
Storage Type
Recommendations:- SSD: 10x faster queries, highly recommended
- NVMe: Best performance for large databases
- HDD: Only for small databases or budget constraints
File System
Best:- ext4 (Linux)
- XFS (Linux, large files)
- APFS (macOS)
- NFS (network latency)
- SMB/CIFS (network latency)
- FAT32 (file size limits)
Docker Volume Performance
Bind Mount (Recommended):Network Optimization
MySQL Network
Latency Impact:- <1ms (same server): Excellent
- 1-10ms (same datacenter): Good
- 10-50ms (same region): Acceptable
- >50ms (cross-region): Increase batch sizes
- Use private network when possible
- Increase
BATCH_SIZEfor high latency - Enable MySQL query cache on source
API Performance
Query API:- Use
LIMITclauses for large result sets - Enable compression for large responses
- Use pagination for table data
- Keep-alive connections
- HTTP/2 for better multiplexing
- CDN for frontend assets
Performance Monitoring
Key Metrics
Sync Performance:- Appender API: 60,000+ rows/sec
- Small batches: 10,000+ rows/sec
- Simple aggregations: <100ms
- Complex joins: <1s
- Report queries: <10s
cpuPercent< 80%rssMB< 80% of availableeventLoopLagMs< 50ms
Configuration Profiles
High Throughput Profile
Goal: Maximum sync speed, high resource usageBalanced Profile (Default)
Goal: Good performance, moderate resource usageLow Resource Profile
Goal: Minimal resource usage, slower performanceBenchmarking
Sync Benchmark
Test sync performance: Calculate rows/second:Query Benchmark
Test query performance:Troubleshooting Performance
Slow Sync
Slow Queries
Optimize SQL
- Add WHERE clauses to filter early
- Use LIMIT for large result sets
- Avoid SELECT * when possible
- Use indexes on join columns
High Memory Usage
Next Steps
- Synchronization - Configure sync operations
- Monitoring - Set up performance monitoring
- Backups - Configure backup automation