Pool Configuration — Aquilia Documentation
Comprehensive guide and documentation for Pool Configuration in the Aquilia framework. View API reference, examples, and implementation patterns.
SQLite / Pool Configuration Pool Configuration Fine-tune the SQLite connection pool settings, sizing limits, PRAGMA parameters, and statement caches for production workloads. Configuring via SqlitePoolConfig All connection pool settings are configured via the SqlitePoolConfig dataclass, which is passed to create_pool() . from aquilia.sqlite import create_pool, SqlitePoolConfig config = SqlitePoolConfig( path="app.db", # Pool sizing & timeouts pool_size=10, # Number of concurrent reader connections pool_min_size=4, # Pre-opened reader connections pool_timeout=30.0, # Wait limit to acquire connection (seconds) pool_max_idle_time=300.0, # Eviction time for idle connections (seconds) # Cache settings cache_size=-16000, # Negative = KiB (16MB memory cache) statement_cache_size=256, # Max cached prepared statements per connection ) pool = await create_pool(config) SQLite Journal Modes Controls how SQLite handles transaction logs on disk. WAL mode is highly recommended as it enables multi-reader concurrency. Journal Mode Description Concurrency Level ))} Synchronous Disk Flushing Determines how aggressively SQLite forces disk syncs (fsync). When using WAL mode, NORMAL is recommended. Sync Mode Disk Flushing Safety Level ))} Performance Optimization Settings Memory-Mapped I/O (mmap_size) Memory-mapping maps database pages directly into host process RAM, bypassing system call read paths. Highly recommended for read-heavy databases. # Enable 256MB memory mapping config = SqlitePoolConfig(mmap_size=268435456) Warning: Set mmap_size=0 for databases that are extremely write-heavy to prevent memory thrashing. Statement Cache (statement_cache_size) Caches prepared SQL queries to eliminate SQL parsing overhead on subsequent executions. # Cache 256 prepared statements per connection config = SqlitePoolConfig(statement_cache_size=256) Uptime & Performance Metrics Inspect connection pool allocations and statements caching hits: # Inspect active connection counters print(f"Total Queries: ") print(f"Active Reader Connections: ") print(f"Average Query Duration: ms") # Inspect statement cache efficiency stats print(f"Prepared Cache Hits: ") print(f"Prepared Cache Misses: ") print(f"Hit Rate Percent: %") )
Go to Homepage