Skip to content

Evaluate the reindex_min_bytes default #1636

Open

Description

@zonotope

DEFAULT_REINDEX_MIN_BYTES is 100 bytes (fluree-db-api/src/server_defaults.rs:31). Any commit's novelty exceeds that, so the default is effectively "build an index after every commit." That was deliberate — 8ad4f65ab ("Update default index min-bytes to 100", 2026-06-29) lowered it from 100_000 and documented the intent in place:

// 100 bytes — effectively reindex after every commit (any commit's novelty
// exceeds this), so the persisted index tracks the head with minimal lag.
pub const DEFAULT_REINDEX_MIN_BYTES: usize = 100;

The same commit reworded the config template from "100 KB — triggers background reindexing" to "bytes of novelty before a background reindex (default ≈ every commit)".

This issue asks whether that trade is right for write-heavy workloads, now that #1548 has given us field evidence about what a build-per-commit costs.

Why now

#1548 reported a single-node file-storage deployment where sustained small commits produced heavy index-artifact churn. Two figures from that report, as measured by the reporter:

  • ~4,100 commits / ~1.2M flakes over ~1h with FLUREE_REINDEX_MIN_BYTES=2000000 produced 3.0 GB on disk for 52 MB of commit data, including ~2,400 dictionary artifacts and 216 index roots.
  • On 4.1.2 defaults, ~370 small captures produced 25 GB across 34k files.

The reporter explicitly noted results were worse at the 100-byte default, and asked for the default to get a second look even after the leak was fixed.

The reclamation work on #1548 bounds the accumulation — superseded artifacts are now reachable and collectable, and a storage sweep reclaims what was already orphaned. It does not change the churn: at one build per commit, the write and CPU cost of producing those artifacts is unchanged, they are simply cleaned up afterward. Reclaiming 25 GB is better than leaking it, but not writing it is better still.

What to evaluate

  1. Per-build cost as a function of ledger size. Forward dict packs are incremental (build_incremental_string_packs emits only entries above the watermark), but the reverse-tree update and root re-publish happen on every build. Measure bytes written per build against ledger size to find out whether per-commit indexing is O(delta) or has an O(ledger) component. File storage: superseded index snapshots/dictionaries are never reclaimed in practice, and POST /reindex permanently breaks the GC chain (root published with no garbage manifest) #1548 asserts the latter for dictionaries; that claim has not been verified in isolation and should be, since it decides whether this is a tuning question or a scaling one.

  2. The freshness the default buys. The stated rationale is minimal index lag. Quantify what lag actually costs — queries over unindexed novelty go through the overlay path, so the trade is query latency on recent data against write amplification. Without that number the default cannot be argued either way.

  3. Whether one default can serve both shapes. A read-heavy ledger with occasional writes and a sustained-ingest ledger want opposite settings. Options worth comparing: raise the static default, scale it from ledger size, or add a time-based floor so bursts coalesce into one build.

Suggested outcome

Either a defended default (with the measurements recorded, so the next person doesn't re-litigate it) or a changed one. If it changes, docs/operations/configuration.md and the config template in server_defaults.rs both carry the value and need updating together — 8ad4f65ab touched both.

Related

Activity

  1. added
    triage:needs-decision
    P2
    area:storage
    on Aug 25, 2026
  2. bplatz commented on Sep 16, 2026

    @bplatz
    Contributor

    Field data point for the "per-build cost as a function of ledger size" question, from the deployment that also produced #1862.

    _system ledger, single branch, file storage: 5,584 index builds over 3 days at the 100-byte default. Decoding one publish's garbage manifest (t=57620) gave:

    Kind Items Bytes
    dictionary blobs (reverse-dict leaves + small packs) 6 8.3 MB
    history sidecars 4 14.8 MB
    leaves 8 8.0 MB

    So roughly 31 MB of index-artifact churn per build against a ledger whose live index and commit log were both far smaller. At 5,584 builds that's the dominant cost, not the freshness this default buys — and #1862 only reclaims that churn after the fact, it doesn't reduce it. Filing as a data point rather than a recommendation, since freshness cost (item 2 above) is unmeasured here.

  3. aaj3f commented on Sep 16, 2026

    @aaj3f
    Contributor

    Answering item 1 of "What to evaluate" directly, since we measured it while looking at something else — and the answer is a third option that isn't on the list.

    Per-build cost is neither O(delta) nor O(ledger). It is O(1) in ledger size with a large constant. A ladder of ledgers, each given one small insert and then an incremental fluree index, measured twice independently:

                     pass 1        pass 2 (load ~21)
      1 k triples :  5.02 s          7.92 s
    100 k triples :  4.95 s          5.17 s
    700 k triples :  5.79 s          5.81 s
    

    Neither pass shows any growth across a 700× range of ledger size. Two runs at different machine loads agreeing on that is the part I would rest the conclusion on.

    The spread between the passes is worth having in front of you rather than tidied away, because it is what makes "flat" a meaningful word here. It shows run-to-run noise on a shared box at around ±3 s — the 1 k point is first in its sequence and carries cold-cache and first-touch effects, so I would not read the ordering within either pass as signal. That noise is the scale against which "no growth" should be read: an O(ledger) term across a 700× range would be enormous and could not hide inside a band this size, so its absence is not an artifact of measurement resolution.

    On the absolutes: roughly 5 s is a good working figure, single-machine, and load was not recorded for the first pass, so I would not present it as a certified floor to two decimal places. The flatness is the finding; the constant is approximate.

    And it extends further down than the ladder goes. A colleague chasing an unrelated annotation defect ran the smallest control that exists — a single-triple ledger — and its incremental build still cost tens of seconds on a loaded box, the same regime as ledgers a million times larger measured under comparable load. I am deliberately not putting that number next to the 5 s ladder above, because it came off a different machine and the two are not commensurable; what it establishes is the direction, which is the part that matters here: the toll does not shrink as the ledger shrinks. A ledger with one triple in it pays it.

    So for this issue's purposes: the 100-byte default means every commit pays the same fixed overhead no matter how little changed, and that overhead does not shrink as the ledger shrinks. That seems to me to strengthen the case for raising the default rather than weaken it — the cost is not amortized against anything.

    This is the time-and-blocking half of the same per-build cost @bplatz measured in bytes above. ~31 MB of artifact churn per build and a fixed multi-second wall-clock toll are the same phenomenon seen through two instruments.

    The shape of the cost, since it constrains the fix

    It is blocking/syscall-bound, not compute and not paging. On a 68 s run (/usr/bin/time -l):

    • user time of 1.4–1.9 s against wall clocks of 65–144 s — so almost none of it is computation;
    • 91,805 voluntary and 177,412 involuntary context switches — to merge four triples;
    • 1 page fault, 0 swaps, 18,182 reclaims, 58 % of system memory free, and vm_stat pageouts moved 1,052,711 → 1,058,258 across the whole run, which is background noise from other builds.

    That looked like paging at first, given the sys time and the memory floor, and it simply isn't — the numbers above refute it. What the profile actually looks like is a large fixed number of small, individually-blocking storage operations.

    Where they are, as far as we have traced: fluree-db-indexer/src/build/incremental.rs, in the V6 Phase-2 branch-update stage. :841 schedules tasks=8 concurrency=4 graphs=2 — that is 2 graphs × 4 index orders, i.e. structural rather than data-driven, which is consistent with the flat line. :653 has each task reporting new_leaf_count=1 while taking 5–8 s. And :3998 spends ~5.8 s writing a 6,114-byte index root.

    One more thing ruled out, which nobody asked for but which pre-empts a plausible wrong guess: a colleague running unrelated annotation work put two single-triple ledgers side by side, one annotated and one not, same machine and same moment, each given one insert and then an incremental fluree index — 92.5 s vs 91.2 s. The annotation path is conclusively not involved.

    Ruled out along the way: a sleep (23–47 s of it is sys), and rayon oversubscription as a cause — it is a ~2× amplifier only (unset 2m19.6 / =2 1m29.1 / =1 1m5.6). One correction to something said earlier in this investigation: fsync is a real contributor at roughly 25 % (1m39.1 against 1m14.5 with FLUREE_STORAGE_FSYNC=0). An earlier "not fsync" was measured at the 5 s scale and was under-powered to see it. That still leaves ~74 s unexplained on a loaded box.

    It is not #1862, and I want to say that explicitly because the two look adjacent. #1862 touches no file under fluree-db-indexer/src/build/ at all — its indexer changes are confined to gc/{collector,mod,siblings,sweep}.rs, orchestrator.rs, config.rs, fuel.rs, and a lib.rs hunk that is purely pub use re-exports. It reclaims what a build produces; it cannot change what a build does, which is what its own "Not covered" note says. The dictionary path is also not the shape it would need to be: compute_affected_leaf_indices (fluree-db-indexer/src/build/dicts.rs:62-165) pre-fetches only affected leaves, so there is no per-build O(ledger) component there to find.

    The inversion, which is the sharpest single statement of the problem

    On the same ledger in the same state, a quiet box, the two commands run back to back:

    incremental  (fluree index)             : real 5.138s   user 0.61s   sys 4.48s
    full rebuild (fluree reindex --direct)  : real 0.043s   user 0.00s   sys 0.02s
    

    The incremental merge is 100×+ slower than rebuilding the whole index from scratch. Of everything here this is the number I would trust most: the pair runs on one ledger seconds apart, so it cannot be a load artifact the way the larger absolutes can.

    The structural reason is that the two commands do not share a pipeline. reindex goes through rebuild_index_from_commits and skips the can_incremental branch (fluree-db-indexer/src/lib.rs:212-217) entirely — so it never enters the Phase-2 stage above. It also runs on a dedicated tokio runtime bounded to two worker threads (fluree-db-indexer/src/build/rebuild.rs:34), where the incremental stage uses the process-global rayon pool. I would not lean on that second difference as the cause, though, and I want to flag why rather than let it read as settled: the doc comment directly above that line says the rebuild's CPU parallelism uses its own thread pools rather than tokio workers, so the thread count there is not obviously the thing doing the work. Treat it as an observed structural difference, not a diagnosis.

    As an interim mitigation, either would help and neither needs the root cause first: route index_ledger to the rebuild path below some ledger size, or bound the incremental stage the way rebuild.rs:34 already bounds the rebuild.

    What is not established

    I would rather name the dead end than have someone else walk into it. We do not know which operation emits the ~92k voluntary handoffs. The obvious next step is to sample the process, and that does not work here: the shipped binary is built with -C strip=symbols, so sample(1) comes back with an empty call graph. Whoever picks this up will need an unstripped build before profiling is worth attempting.

    The ~74 s residual on a loaded box is likewise unattributed — fsync accounts for roughly a quarter and rayon oversubscription amplifies by about 2×, and that does not add up to the whole.

    On the numbers

    Two things worth stating so nobody quotes these wrongly.

    The working figure is ~5 s. It is not 68 s or 92 s or 144 s. Those larger figures are all from shared boxes under load averages of 12 to 41, and they sit on a smooth curve with load — which is itself informative, given the blocking profile above, but none of them is the cost of an index build. Where a comparison is being drawn, the pairing is the claim and the magnitude is not.

    The ~190 MiB memory figure is a floor, not a constant. Peak RSS drifts 186.5 → 199.5 → 229.2 MiB across the 1 k → 700 k ladder, so it is one large fixed allocation with a small data-proportional part on top. And it does not generalize upward: at the 700 k base the full rebuild peaks higher (249 MiB) than the incremental run does. What is anomalous is the floor relative to the work — 186 MiB to merge four triples, 8.5× what a full rebuild of the whole ledger costs at that size — not the absolute number at scale.

    All single-machine, M-series macOS, main @ 3d89e8f71.

  4. bplatz commented on Oct 22, 2026

    @bplatz
    Contributor

    Another field report, from an R2RML materialize workload writing into a ledger at a high commit rate:

    • each incremental build rewrites ~550 objects;
    • dictionaries dominate disk;
    • size per version hasn't been measured.

    This fits the fixed per-build cost above. The retention half of that report, where the 15-minute age guard rather than max_old_indexes decides how many of those versions stay on disk, is now #2164.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2area:storagetriage:needs-decision

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions