docs/ref/modules/utils/sync-protocol/persistence-performance.md
The Agent Sync Protocol uses SQLite as its persistent storage backend, configured with Write-Ahead Logging (WAL) mode to optimize performance for high-throughput write operations. This document provides technical justification and performance analysis supporting the use of WAL mode in the persistent queue implementation.
The WAL configuration is set in the PersistentQueueStorage constructor:
File: src/shared_modules/sync_protocol/src/persistent_queue_storage.cpp
m_connection.execute("PRAGMA synchronous = NORMAL;");
m_connection.execute("PRAGMA journal_mode = WAL;");
Performance testing confirms that enabling Write-Ahead Logging (WAL) mode provides significant performance improvements, particularly for File Integrity Monitoring (FIM), which is the module with the highest load.
| Platform | Journal Mode | Scan Duration | Performance Improvement |
|---|---|---|---|
| Linux | WAL enabled | 24 seconds | 2.0× faster |
| Linux | Default (DELETE) | 48 seconds | Baseline |
| Windows | WAL enabled | 100 seconds | 2.85× faster |
| Windows | Default (DELETE) | 285 seconds | Baseline |
FIM scans generate high-volume, sequential write operations as file checksums are recorded. WAL mode optimizes this pattern by:
.wal file (sequential I/O)The larger performance gain on Windows (2.85× vs 2.0×) is due to NTFS/Win32 characteristics:
fsync()While the improvement is smaller on Linux, WAL mode still provides:
WAL mode with PRAGMA synchronous = NORMAL provides optimal balance:
| Benefit | Impact |
|---|---|
| Performance | 2-3× faster FIM scans |
| Scalability | Better handling of large file sets |
| SSD Longevity | Sequential writes reduce wear leveling |
| Reliability | Crash-safe with atomic commits |
| Concurrency | Readers don't block writers (if needed in future) |
The Agent Sync Protocol uses a transaction-per-event approach, where each file operation is wrapped in its own BEGIN/COMMIT transaction. Performance testing validates this approach:
With BEGIN/COMMIT per event (current implementation):
Without BEGIN/COMMIT (agent_sync_protocol disabled):
The measured overhead of BEGIN/COMMIT per file operation:
57 seconds (with transactions) - 53 seconds (without) = 4 seconds overhead
This represents only ~7% of total scan time (4s / 57s ≈ 7%), demonstrating that:
PRAGMA synchronous = NORMAL; // Balance between safety and performance
PRAGMA journal_mode = WAL; // Write-Ahead Logging mode
synchronous = NORMAL:
journal_mode = WAL:
.wal fileThe evidence demonstrates that WAL mode provides substantial performance benefits for FIM operations, with improvements ranging from 2× on Linux to 2.85× on Windows. Beyond speed improvements, WAL mode delivers:
The transaction-per-event approach with WAL mode represents an optimal balance of:
This configuration is well-suited for the Agent Sync Protocol's write-heavy workload patterns and should be maintained as the standard persistence strategy.
src/shared_modules/sync_protocol/src/persistent_queue_storage.cpp