Conversation
roberth
left a comment
There was a problem hiding this comment.
No wonder we've been getting sqlite busy warnings. Great find!
I've given it a superficial look, as I'm not too familiar with the eval cache yet.
Maybe @thufschmitt or @edolstra could finish review?
|
The reason that we're not using WAL / small transactions is that (at least at the time) there was significant overhead to using them while populating the cache, especially for something like Nixpkgs. Can you benchmark the performance of something like |
|
Yes, that is right indeed. While WAL does help a lot, transaction do appear to have some overhead: |
|
But then, we cannot reasonably keep a write lock on the database for the whole duration of the Would you consider a patch that performs only reads, and then writes all the computed data at once, when the cursors are destroyed ? It would still be efficient, and more friendly to concurrent accesses to the database. |
|
@layus Yeah that sounds good. An alternative might be (if possible) to start with a read lock and only upgrade to a write lock if we actually need to make changes to the database. Or to disable the eval cache if we can't acquire a write lock. Then it would be slower but at least it wouldn't be blocked. |
Motivation
This commit makes evaluation caches behave properly in presence of parallel
users. Transactions and SQL statements themselves are designed in such a way
that there cannot be race conditions while keeping transaction very small.
(Transactions used to last for the whole lifetime of the cache).
On top of #10570 it enables to significantly speed up evaluation of a large
number of attributes by splitting them across several calls to nix.
From rough measurements on 16 cores it goes from 12s to 5s for ~200 attributes in the same flake.
This also fixes a wide range of issues discovered during the implementation,
like the
insert or updatestatements that would create a brand new rowid andsilently make all the children of the old rowid unreachable, invalidating
significant portions of the cache.
This code has been stress-tested a bit, so it should be devoid of obvious mistakes.
Context
Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.