Skip to content

Use WAL mode for SQLite cache databases#150

Merged
grahamc merged 3 commits intodetsys-mainfrom
concurrent-eval-cache
Jul 16, 2025
Merged

Use WAL mode for SQLite cache databases#150
grahamc merged 3 commits intodetsys-mainfrom
concurrent-eval-cache

Conversation

@edolstra
Copy link
Collaborator

Motivation

With "truncate" mode, if we try to write to the database while another process has an active write transaction, we'll block until the other transaction finishes. This is a problem for the evaluation cache in particular, since it uses long-running transactions.

WAL mode does not have this issue: it just returns "busy" right away, so Nix will print

error (ignored): SQLite database '/home/eelco/.cache/nix/eval-cache-v5/...' is busy

and stop trying to write to the evaluation cache. (This was the intended/original behaviour, see AttrDb::doSQLite().)

A quick benchmark (running nix search github:NixOS/nixpkgs/bf8462aeba50cc753971480f613fbae0747cffc0?narHash=sha256-bPyv7hsbtuxyL6LLKtOYL6QsmPeFWP839BZQMd3RoUg%3D 20 times) did not show a significant performance difference:

user CPU time:      median =     16.2447  mean =     16.2527  stddev =      0.1150  min =     16.0922  max =     16.4433  [not rejected, p=0.90746, Δ=-0.00431±0.11047]
elapsed time:       median =     20.2731  mean =     20.2867  stddev =      1.1840  min =     18.8877  max =     21.6970  [not rejected, p=0.80504, Δ=-0.10797±1.30295]

Context

edolstra added 3 commits July 15, 2025 18:09
Instead of

  error (ignored): error: SQLite database '...' is busy

we now get

  error (ignored): SQLite database '...' is busy
With "truncate" mode, if we try to write to the database while another
process has an active write transaction, we'll block until the other
transaction finishes. This is a problem for the evaluation cache in
particular, since it uses long-running transactions.

WAL mode does not have this issue: it just returns "busy" right away,
so Nix will print

  error (ignored): SQLite database '/home/eelco/.cache/nix/eval-cache-v5/...' is busy

and stop trying to write to the evaluation cache. (This was the
intended/original behaviour, see AttrDb::doSQLite().)
@github-actions
Copy link

@github-actions github-actions bot temporarily deployed to pull request July 15, 2025 16:34 Inactive
@grahamc grahamc added this pull request to the merge queue Jul 16, 2025
Merged via the queue into detsys-main with commit c299fba Jul 16, 2025
33 checks passed
@grahamc grahamc deleted the concurrent-eval-cache branch July 16, 2025 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants