perf(db): checkpoint WAL less often
- commit
- 8ab804609d6d2c19a7a685b129c8d9fdd94c1d20
- author
- bnema · · 2025-12-06 02:49 UTC
- parent
- 11bef86
- signature
- unsigned
1 file · +7 -6
M internal/db/init.go +7 -6
| @@ -39,12 +39,13 @@ func InitDB(dbPath string) (*sql.DB, error) { | |||
| 39 | 39 | ||
| 40 | 40 | // Configure SQLite for optimal performance | |
| 41 | 41 | pragmas := []string{ | |
| 42 | - | "PRAGMA journal_mode = WAL", // Write-Ahead Logging: 70k reads/sec, 3.6k writes/sec, concurrent access | |
| 43 | - | "PRAGMA synchronous = NORMAL", // Safe in WAL mode, only checkpoints wait for FSYNC | |
| 44 | - | "PRAGMA cache_size = -64000", // 64MB cache (default is only ~2MB) | |
| 45 | - | "PRAGMA temp_store = MEMORY", // Temporary tables in RAM | |
| 46 | - | "PRAGMA mmap_size = 30000000000", // 30GB memory-mapped I/O (virtual memory, OS-managed) | |
| 47 | - | "PRAGMA busy_timeout = 5000", // Wait 5 seconds on lock contention | |
| 42 | + | "PRAGMA journal_mode = WAL", // Write-Ahead Logging: 70k reads/sec, 3.6k writes/sec, concurrent access | |
| 43 | + | "PRAGMA synchronous = NORMAL", // Safe in WAL mode, only checkpoints wait for FSYNC | |
| 44 | + | "PRAGMA cache_size = -64000", // 64MB cache (default is only ~2MB) | |
| 45 | + | "PRAGMA temp_store = MEMORY", // Temporary tables in RAM | |
| 46 | + | "PRAGMA mmap_size = 30000000000", // 30GB memory-mapped I/O (virtual memory, OS-managed) | |
| 47 | + | "PRAGMA busy_timeout = 5000", // Wait 5 seconds on lock contention | |
| 48 | + | "PRAGMA wal_autocheckpoint = 2000", // Checkpoint every 2000 pages (~8MB) instead of default 1000 (~4MB) | |
| 48 | 49 | } | |
| 49 | 50 | ||
| 50 | 51 | for _, pragma := range pragmas { | |
| @@ -39,12 +39,13 @@ func InitDB(dbPath string) (*sql.DB, error) { | |||||
| 39 | 39 | ||||
| 40 | // Configure SQLite for optimal performance | 40 | // Configure SQLite for optimal performance | ||
| 41 | pragmas := []string{ | 41 | pragmas := []string{ | ||
| 42 | - | "PRAGMA journal_mode = WAL", // Write-Ahead Logging: 70k reads/sec, 3.6k writes/sec, concurrent access | 42 | + | "PRAGMA journal_mode = WAL", // Write-Ahead Logging: 70k reads/sec, 3.6k writes/sec, concurrent access |
| 43 | - | "PRAGMA synchronous = NORMAL", // Safe in WAL mode, only checkpoints wait for FSYNC | 43 | + | "PRAGMA synchronous = NORMAL", // Safe in WAL mode, only checkpoints wait for FSYNC |
| 44 | - | "PRAGMA cache_size = -64000", // 64MB cache (default is only ~2MB) | 44 | + | "PRAGMA cache_size = -64000", // 64MB cache (default is only ~2MB) |
| 45 | - | "PRAGMA temp_store = MEMORY", // Temporary tables in RAM | 45 | + | "PRAGMA temp_store = MEMORY", // Temporary tables in RAM |
| 46 | - | "PRAGMA mmap_size = 30000000000", // 30GB memory-mapped I/O (virtual memory, OS-managed) | 46 | + | "PRAGMA mmap_size = 30000000000", // 30GB memory-mapped I/O (virtual memory, OS-managed) |
| 47 | - | "PRAGMA busy_timeout = 5000", // Wait 5 seconds on lock contention | 47 | + | "PRAGMA busy_timeout = 5000", // Wait 5 seconds on lock contention |
| 48 | + | "PRAGMA wal_autocheckpoint = 2000", // Checkpoint every 2000 pages (~8MB) instead of default 1000 (~4MB) | |||
| 48 | } | 49 | } | ||
| 49 | 50 | ||||
| 50 | for _, pragma := range pragmas { | 51 | for _, pragma := range pragmas { | ||