Daemon's output capture backends: reason to choose fjall, and possible alternatives

In PR 4082, the daemon had its output capture functionality split into two backends: fjall, and nop. The reason behind nop is trivially obvious. The reason behind a data store, in general, is obvious too; but less for the specific implementation, or even the choice to go KV.

From what I can gather, the output_capture module just.. captures command output, for later use. It does fit well in a KV database, though it’s probably also okay-ish to reside in a SQL database, like SQLite, as TEXT blobs.

The reasoning behind using fjall is unclear to me. It’s not a big deal, but does pose some extra efforts in packaging: 7 unpackaged dependencies (might be able to get rid of one or two), 8 trips through NEW.

Compared, rocksdb, which fjall itself describes as being similar to, is readily available in Debian (more precisely, the C lib and the Rust bindings crate), and I suppose similarly in other distros.

lmdb is a similar alternative just like rocksdb, with C lib and Rust bindings readily available.

redb is a pure Rust KV database, not packaged yet, but only one package and NEW trip away.

SQLite is an interesting alternative: not a KV database by strict definition, but stores a few thousands of KV-like records just fine, without further requirements.

There’s also the problem of how many backends are enough. This does not seem like a use case to have multiple, competing backends. At most, SQLite/KV/nop, and only when SQLite is meaningfully different than KV to the user.

This all comes down to the design and expectation of the module/functionality, not merely “the dependency is not packaged”.

At the very least, we could always patch this feature out first, as it seems to be disabled by default at the moment. This is mostly a curiosity and preparation for later when it’s being enabled.

1 Like

So we opted for non-SQLite here intentionally, mostly for disk usage reasons. The scale is bigger than it might look. We’re (optionally) capturing output for every command, so we expect there to be 10s to 100s of 1000s of records per user machine, most of them small. The concern is much more about disk usage than it is about performance.

That’s where an LSM does well. Fjall compresses at the block level, across many records, which matters when most values are too small to compress well individually. SQLite has no built-in compression, and lmdb and redb are B-tree stores without it either.

RocksDB would give us the same properties, but we wanted to stay pure Rust where we can. It keeps cargo install, cross-compilation and our release binaries simple. I appreciate that the tradeoff runs the opposite way for distro packaging, and that the NEW trips are a real cost.

We only intend on supporting one backend, but if fjall turns out not to be suitable, RocksDB is the first place we’d look.

If you can share the list of the 7 unpackaged deps, we’ll also check whether any can be dropped or feature-gated on our side!

Understood, sounds like a reasonable and thoughtful choice to me. I share the concern of external libraries as an occasional upstream.

Dependency graph of fjall, listing only unpackaged:

fjall
|- lsm-tree
   |- byteview
   |- crossbeam-skiplist
   |- interval-heap
   |- quick_cache
   |- sfa
   |- varint-rs

We might be able to replace, for example, quick_cache with another cache library packaged in Debian; and inline a dependency or two if the code actually used is very small. Most of the time consumed for filling up this gap would be in the NEW trips, where the DFSG team has to read through all of their code for license and copyright problems.

On the other hand, purely out of curiosity, I’m also in the process of writing a redb backend and benchmarking the two, sharing the numbers when ready. I do hope a few bucks would prove it’s worth saving later maintenance burden for quite a few packages; but even when not, don’t worry too much, as the routine maintenance is very simple for each, it’s more of a mental load than actual keyboard bumping.

Update: added SQLite in the mix.

Here are the numbers! Read the analysis for details.

For this simulated workload, SQLite gave the most predictable final disk usage: after compaction and reopening, it was smaller than redb in all runs; its size is the same as long as the seed is the same, almost reproducible. Fjall often came out a little smaller than SQLite, but sometimes much larger. In one set of repeats with the same seed, VM and engine order, it finished at about 106 MiB three times and 263 MiB once. I don’t know what’s behind that yet. This only compares disk usage, though; it isn’t enough on its own to recommend switching backends.

Also I’m not 100% sure this is representative for enough users, but am happy to update it and re-run the numbers.

I should add that this is by no means pushing you to change backend, it’s just curiosity leading me here and providing a reference of sorts.