Commit fe169cb
committed
Make explicit non-passive Sqlite WAL checkpoints
The default way SQLite in WAL mode performs checkpoints, is by waiting
for quiet time where there are no readers nor writers.
Any read-connection can block this passive WAL checkpointing from making
progress. We have observed that in production when having large
workloads with consumers working on hundreds of chunks concurrently.
Whereas the WAL is not expected to grow much beyond 4MiB (that's when
the passive autocheckpointing kicks in), we saw WALs of > 850MiB. At
that point, reads slow down significantly and that can cause a failure
for the system as a whole.
To mitigate this, as per the SQLite docs, this PR:
- Disables the passive autocheckpointing (leaving it enabled conflicts
with manual checkpointing which can then result in a SQLITE_BUSY)
- Runs active checkpointing _every second_. It is very fast when there
is little-to-no work to do, but under load it is expected that we'll
hit the '1000 page mutations' (AKA the 4MiB default WAL size) within a
second.
- We use the 'RESTART' strategy, together with a `journal_file_limit`
that ensures that the WAL will be trimmed down to the max of 4MiB.
That means we don't always fully truncate, nor do we keep it at
'whatever the max happened to be'.
Doing this checkpointing does mean that every second there is a tiny
timeframe in which both write-tasks and also all read-tasks will have to
wait. This is unlikely to cause any problems. We now explicitly
configure the busy timeout to be 5 seconds, which was the prior implicit
default of SQLx/Rusqlite for good measure.1 parent 1efa6a6 commit fe169cb
3 files changed
Lines changed: 35 additions & 3 deletions
File tree
- libs/opsqueue_python/examples/integer_increment
- opsqueue
- app
- src/db
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
244 | 266 | | |
245 | 267 | | |
246 | 268 | | |
| |||
366 | 388 | | |
367 | 389 | | |
368 | 390 | | |
369 | | - | |
| 391 | + | |
| 392 | + | |
370 | 393 | | |
371 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
372 | 399 | | |
373 | 400 | | |
374 | 401 | | |
| |||
412 | 439 | | |
413 | 440 | | |
414 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
415 | 445 | | |
416 | 446 | | |
417 | 447 | | |
| |||
0 commit comments