Skip to content

Compare the durable Doublets store with SQLite File, tune SQLite, and measure the file-backed stores under memory limits - #179

Open
konard wants to merge 30 commits into
mainfrom
issue-127-8556896db129
Open

konard wants to merge 30 commits into
mainfrom
issue-127-8556896db129

Conversation

@konard

@konard konard commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

The non-volatile Doublets rows were labelled as comparisons with SQLite of the same durability. SQLite File fsyncs its rollback journal and database at every COMMIT, while the mapped Doublets stores have no journal and never sync. This change measures the durable pairing the README claimed and gives SQLite a configuration that matches a fully mapped store. It also adds tables for the file-backed stores under memory pressure. The libraries are bumped to their latest releases, and the bugs in them that stand in the way of the closest comparison are reported upstream, each with a workaround in this repository.

Fixes #127.

Changes

Request 1: the transactional Doublets row at 10M

  • Doublets_United_NonVolatile_Transactional (Rust, opt-in links variant) puts the united file-mapped store behind doublets' TransactionsDecorator, with the shipped FileTransitionLog, which calls sync_all after every record.
  • The journal policy is left exactly as shipped. Each lifecycle phase that writes is one transaction: it begins at the phase's first write and commits at the phase's end, so the read phases begin none.
  • It is published next to SQLite File (stock defaults, synchronous=FULL) in a new "Durable file storage" section at 10,000,000 links, 32 and 64 bit, with --repetitions 1.
  • The plain NonVolatile rows are now described as "file-backed without durability guarantees" in both READMEs.

Request 2: SQLite's configuration

  • A new SQLite File Tuned row runs PRAGMA cache_size = -1048576; PRAGMA mmap_size = 1073741824; before the schema is created.
  • It exists in Rust (SQLite_File_Tuned) and in both C# providers (SQLite_File_Tuned on Microsoft.Data.Sqlite, SystemDataSQLite_File_Tuned on System.Data.SQLite).
  • The file-backed Doublets rows are compared with it wherever it was measured.

Request 3: memory pressure

  • SQLite_File, Doublets_United_NonVolatile and Doublets_Split_NonVolatile (32 bit) run inside a systemd-run --scope with MemoryMax, MemorySwapMax=0 and --repetitions 1:
    • 24 MiB at 1,000,000 links;
    • 240 MiB at 10,000,000 links.
  • Under pressure a store can take hours, so each storage runs in its own job of one run. The report merges the jobs' reports into one table per limit, labelled with the limit, after checking that they share the run, the commit, the software and the configuration.
  • A second table under each one shows every job's runner, disk latencies, cgroup memory.peak and major page faults. The provenance line shows memory.high and the dirty page thresholds.
  • Both configured kinds record the disk the stores use: the median O_DIRECT random 4 KiB read latency and the fsync latency.
  • The READMEs state that the transactional store cannot take part, because its decorator keeps every transition and a full snapshot of the links in memory. The report validation rejects a memory-limit report that contains it.

Pipeline

  • .github/workflows/configurations.yml plans and runs the configured jobs.
  • scripts/benchmark_configuration.py provides plan, probe, record and report. The configured reports are kept in docs/benchmarks/configurations and validated separately from the default reports, and the README sections are generated from them.
  • Pull requests run a small smoke plan. The published tables come from runs on this branch (see Validation).
  • A memory-limited job gives its storage minutes (a dispatch input, at most and by default 340), then stops it with timeout. The benchmark's --phases log keeps the phases it finished, and benchmark_configuration.py unfinished turns that log into the store's report.
  • scripts/memory_limit_run.sh samples the scope after a minute and then every 15 minutes: the benchmark's state and wait channel, its file, dirty and writeback pages, major faults, and memory and I/O pressure. At the end it writes memory.peak, memory.stat and memory.events, which outlive an OOM kill.

Latest dependencies

Dependency Version
doublets (Rust) 0.21.0
platform-mem 0.4.0
rusqlite 0.43.0, bundling SQLite 3.54.1
Platform.Data.Doublets 1.0.0
Platform.Data.Doublets.Sequences 0.6.5
Microsoft.Data.Sqlite 11.0.0, bundling SQLite 3.53.4
System.Data.SQLite 2.0.4
  • doublets 0.21.0 fixes the 0.5.0 growth and split self-reference bugs, so those workarounds are removed. experiments/unit_store_growth and experiments/split_store_delete pass on it.
  • Npgsql.EntityFrameworkCore.PostgreSQL 11.0.0 targets only net11.0, according to its NuGet catalog entry, so it stays at 10.0.3 on net10.0.
  • link-cli and links-notation are not used by this repository, so there is nothing to bump.
  • The Rust and C# tables use different SQLite engine versions (3.54.1 and 3.53.4), as bundled by their providers. The provenance lines record both.

Upstream bugs reported, with the workarounds kept here

Memory-limit OOM root causes

The 24 MiB job was killed twice, for two different reasons. The kernel stats are in the job logs.

  1. Zero-filled reservation (doublets-rs#95 above): the reservation was written over with zeros. Fixed by ZeroExtended.

    • mapped_stores_do_not_write_their_reservation_and_reopen_with_their_links checks on Linux that the reservation stays unallocated and that the store reopens with its links.
    • On APFS the extension is allocated anyway (macOS 15, run 45603348935), so the check runs on Linux only, where the memory-limit runs happen.
  2. Dirty and writeback pages that reclaim cannot free. Each setting below was tried in a dispatch of the 24 MiB, 1M-link table. The job logs have the scope samples and the final memory.stat and memory.events.

    Setting Run Outcome
    Kernel defaults, vm.dirty_ratio 20%, vm.dirty_background_ratio 10% 45604850024 United store killed (oom_kill 1): 21.6 MiB of file pages, all dirty, 15.7 MiB under writeback.
    vm.dirty_bytes and vm.dirty_background_bytes at 20% and 10% of the limit 45681559798 Every store, SQLite too, waited in balance_dirty_pages with I/O pressure and no memory pressure.
    vm.dirty_ratio 5%, vm.dirty_background_ratio 2% 45683252380 SQLite and the split store run under real memory pressure (read waits, major faults). The united store was killed 4 s into create: 23.3 MiB of file pages, all under writeback.
    The same, plus strict_limit on the storage disk's bdi 45685437372 No kill, but the mapped stores were throttled in balance_dirty_pages to about 3 MiB of file pages in 6 minutes, with no memory pressure.
    The same ratios, plus memory.high at 7/8 of the limit (kept) 45687063141 No kill (max 0, oom_kill 0), peak at most 21.8 MiB. All three stores run under memory pressure: the united store had 448,638 major faults in 6 minutes.
    • Byte thresholds: for a cgroup, domain_dirty_limits in mm/page-writeback.c converts byte thresholds into a ratio of the runner's available memory, rounded up to 1/4096 ("The byte settings can't be applied directly to memcg domains. Convert them to ratios by scaling against globally available memory."). It then applies that ratio to the memory the cgroup can use, so under 24 MiB the cgroup's thresholds came to a few pages. Earlier commits of this PR described the byte values as the cgroup's thresholds, which was wrong.
    • Ratios alone: balance_dirty_pages compares the cgroup's dirty and writeback pages with its thresholds using mem_cgroup_wb_stats. That function reads the memcg counters after mem_cgroup_flush_stats_ratelimited (mm/memcontrol.c), and the counters are flushed every 2 s (FLUSH_TIME). In that window the united store, at about a microsecond per link, dirtied the whole limit. Reclaim cannot free pages under writeback, so the charge failed. This explanation comes from the kernel sources (v6.11) and the stats above. It was not confirmed with a kernel trace.
    • memory.high: a task above it reclaims and sleeps on its way back to user space (mem_cgroup_handle_over_high), which gives the writeback time to finish before memory.max. The limit stays memory.max, and memory.high is recorded in the report and shown in the provenance line.

Reproduction and regression coverage

  • Rust (rust/tests/storages.rs):
    • every_optional_links_variant_passes_the_lifecycle runs the tuned and transactional variants through the checked lifecycle.
    • transactional_store_commits_one_transaction_per_written_phase and transactional_store_journals_writes_outside_a_phase_one_by_one read the journal entries.
    • mapped_stores_keep_their_links_when_their_memory_grows and the reservation test above cover growth.
  • C# (StoragesTests.cs): SQLiteVariantsAreRegistered and TunedSQLiteFilesApplyThePragmas read the pragmas back from both providers.
  • Python (scripts/test_benchmark_configuration.py, scripts/test_benchmark_report.py) covers:
    • plan validation, with one job per storage under a limit, the disk probe, cgroup stats parsing and recording, including the dirty thresholds, which are refused for a durable report;
    • merging the per-storage reports of one table in the configured order, and refusing reports from different runs, duplicated storages, a table without SQLite File and duplicated durable reports;
    • rejection of invalid configured reports (the transactional store under a limit, a missing limit or latency, invalid thresholds);
    • the rendered sections in both languages;
    • an exact match between the committed READMEs and the generator.

Run the configured benchmarks locally as described in README "Configured benchmarks". Regenerate the READMEs with:

python scripts/benchmark_report.py docs/benchmarks/results \
  --configurations docs/benchmarks/configurations \
  --readme README.md --readme README.ru.md --charts docs/benchmarks

Validation

Durable tables (run 45604850024):

  • Measured on PR head 4caf6c2, merged with main 870ddc7, on an Intel Xeon 6975P-C runner, 32 and 64 bit.
  • Since that run, the only Rust changes are in rust/src/harness.rs and rust/src/main.rs. They add the --phases log and leave the measured code as it was.
  • At 32 bit the transactional store compared with SQLite File:
    • 37.4× slower to create, 8.79× slower to update and 13.5× slower to delete;
    • 21.9× faster to read all and 52.3× faster to read by id;
    • a 1,930 MiB file against 501 MiB.

Memory-limit tables (run 45689097621):

  • The full plan, dispatched on 326f6e1. The commits after it change only a docstring and publish the reports.

  • No store was killed. Every job's memory.events shows max 0 and oom_kill 0. Peaks were 21.2 to 21.7 MiB under 24 MiB, and 210.2 to 213.3 MiB under 240 MiB.

  • SQLite File finished both tables: in 18 minutes at 1M links, and in 5 hours at 10M.

  • The Doublets stores ran under real memory pressure: 21 to 56 million major page faults per job. Each was stopped after 340 minutes:

    Limit United store stopped in Split store stopped in
    24 MiB, 1M links update delete
    240 MiB, 10M links create query_by_from_to
  • A stopped store's row keeps the phases it finished, gives a lower bound (>) for the phase in progress and — for the rest, and a note under the table names it.

  • The jobs ran on different runners: Intel Xeon 6975P-C, Xeon Platinum 8573C, AMD EPYC 7763 and EPYC 9V74. The second table under each limit lists every job's runner and the disk's random 4 KiB read and fsync latencies.

Local checks on the final commit:

  • 92 Python tests, including the exact match between the committed READMEs and the generator;
  • ruff format --check and ruff check on scripts and experiments;
  • mypy scripts and bandit -r scripts experiments;
  • dotnet build of the C# solution;
  • lizard: no function in scripts has a cyclomatic complexity above 15;
  • markdownlint-cli 0.49.1 on README.md, README.ru.md and CONTRIBUTING.md;
  • scripts/ci_checks.py.

Static analysis (Codacy, CodeFactor):

  • The multi-line docstrings that Codacy's pydocstyle flagged (D205, D209, D213, D415) are now one-line docstrings, with the details moved into comments.
  • SQLiteStorage.Tuning is a static read-only property instead of a const (Sonar S2339). The pragmas constructor parameter is required instead of optional (S2360); every caller already passed it.
  • CodeFactor keeps reporting a complex method at the lines where it first found it (273-303, validate_configuration at 17a6478). validate_configuration, merge_jobs, plan, unfinished and provenance are split into helpers, and the output is unchanged.

The Rust, C#, Benchmarks, Configured benchmarks (smoke plan), CI quality and Dependency audit workflows run on the pull request.

Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: #127
@konard konard self-assigned this Nov 25, 2026
…onal Doublets variant

doublets 0.21.0 fixes the growth of the store memory and the split store
self-reference update, so memory::Whole and the update to (0, 0) are gone;
experiments/unit_store_growth and experiments/split_store_delete pass on it.

SQLite_File_Tuned runs PRAGMA cache_size = -1048576 and mmap_size = 1 GiB
before the schema. Doublets_United_NonVolatile_Transactional is an opt-in
links variant: the united store behind TransactionsDecorator with the shipped
FileTransitionLog, one transaction per lifecycle phase begun on its first write.
…0.0, add the tuned SQLite file variants to C#

Both providers run PRAGMA cache_size = -1048576; PRAGMA mmap_size = 1073741824;
before the schema in SQLite_File_Tuned and SystemDataSQLite_File_Tuned.
…e transactional store and the memory limit

Configured reports (durable, memory_limit) live in docs/benchmarks/configurations, are validated
separately from the default reports and render as their own README sections. File-backed Doublets
rows are compared with SQLite File Tuned where it was measured, the transactional store with SQLite File.
benchmark_configuration.py plans the runs, probes the disk's random 4 KiB read and fsync latency,
and records the cgroup limit, peak and major faults.
…n the PostgreSQL check, the unit_store_growth lockfile

experiments/unit_store_growth depends on the rust crate, so its lockfile follows rusqlite 0.43.0.
doublets 0.21.0 grows its memory with grow_filled(Default), and FileMapped of
platform-mem 0.4.0 writes the fill over the whole set_len extension, so a fresh
32-bit united store dirties 32 MiB of mapped pages before its first link: the
24 MiB memory-limit run was OOM-killed at 20,000 links. ZeroExtended reports
the zero extension as initialized, so the reservation stays a hole.

The configured workflow keeps the scope alive on an OOM kill and prints the
cgroup stats before failing; os-release is read without sourcing it (SC2031).
…e_returning experiment to rusqlite 0.43.0 (RUSTSEC-2026-0459)
…figured benchmarks and the current upstream bugs in the READMEs
… ratios of the limit

The united store was killed under 24 MiB (run 45604850024): the kernel's
thresholds, computed from the whole runner, let it dirty 21 MiB of its
mapping before writeback throttled it. The thresholds are recorded in the
reports and shown in the tables. The temporary plan now measures only the
memory-limit runs; the durable jobs of run 45604850024 keep running.
… to SQLite File and SQLite File Tuned

Measured on this pull request in run 45604850024 (32 and 64 bit, 10,000,000
links, --repetitions 1).
…reports into one table

Under 24 MiB the united store had not finished after 91 minutes, so the three storages of a
1,000,000-link table, and certainly of a 10,000,000-link one, would exceed the job time limit
together. The plan now gives each storage its own job; the report merges the jobs of one run
into one table and shows each job's runner, disk latencies, peak cgroup memory and major page
faults in a second table.
…rnel applies them to the cgroup

Byte thresholds are scaled to a cgroup as a fraction of the runner's memory
(domain_dirty_limits in mm/page-writeback.c), so the cgroup's own thresholds are
a few pages under 24 MiB, not 20% of the limit. The plan step no longer masks a
failure of the plan command.
… in the README example

benchmark_report.py needs default reports, which a local results directory lacks.
@konard konard changed the title [WIP] "Same durability" comparison: run Doublets 0.8.0 behind its own transaction journal (fsync per write) against SQLite File at 10M, and add a memory-pressure configuration Compare the durable Doublets store with SQLite File, tune SQLite, and measure the file-backed stores under memory limits Nov 25, 2026
…memory-limit tables

SQLite reads its file with read, so its misses under the limit show as 0 major faults.
…he phases it finished

The Doublets jobs under 24 and 240 MiB ran into the 355-minute job limit
without a report. The benchmark now logs each measured phase as it begins and
ends with --phases; scripts/memory_limit_run.sh runs it for at most 340 minutes
inside the scope and samples the scope's wait channel, dirty and writeback
pages, major faults and pressure every 15 minutes. A stopped run is reported
by benchmark_configuration.py unfinished: the finished phases, a lower bound
for the phase in progress and — for the rest, with a note under the table.
…ives its storage, and run the pull request plan when the runner script changes
…g byte thresholds, which the kernel scales down to a few pages for a cgroup
…hrottling counts the cgroup's own writeback pages
…ict_limit on its disk, which throttled the mapped stores to a crawl
…lets stores under 24 MiB at 1M links and 240 MiB at 10M

From the full plan of run 45689097621 on 326f6e1. No store was OOM-killed (memory.events max 0,
oom_kill 0). SQLite File finished both tables; the Doublets stores were stopped after 340 minutes,
and their rows keep the phases they finished and a lower bound for the phase in progress.
@konard
konard marked this pull request as ready for review November 26, 2026 01:40
@konard

konard commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Working session summary

All three requests of #127 are done, and PR #179 is marked ready for review: #179. CI passed on the final commit (a517546), the working tree is clean, main is merged in, and there's no new feedback on the issue or the PR.

The last piece was the memory-pressure tables, published from run 45689097621:

  • No store was killed for running out of memory. Every job's memory.events shows max 0 and oom_kill 0. Peak memory was 21.2–21.7 MiB under the 24 MiB limit and 210.2–213.3 MiB under 240 MiB. Earlier runs had the united store killed; setting memory.high to 7/8 of the limit is what stopped that.
  • SQLite File finished both tables: in 18 minutes at 1M links and in about 5 hours at 10M.
  • None of the Doublets stores finished. They ran under real memory pressure, with 21 to 56 million major page faults per job, and each was stopped at the 340-minute job limit:
  | Limit | United store stopped in | Split store stopped in |
  | --- | --- | --- |
  | 24 MiB, 1M links | `update` | `delete` |
  | 240 MiB, 10M links | `create` | `query_by_from_to` |

Their rows keep the phases they finished, show a lower bound (>) for the phase in progress and — for the rest, and a note under each table says they were stopped. The united store at 240 MiB never got past create, so its row has only a lower bound of more than 2.04 ms per link. Under these limits the mapped stores are 4.6× to 54× slower than SQLite on most operations; only "read all" is faster (4.7–5.4×).

  • The jobs ran on different machines (two Intel Xeon models and two AMD EPYC models). A second table under each limit lists every job's machine and disk latencies.

The durable tables come from an earlier run, 45604850024. Since then the only Rust changes add the phase log, so what they measure is unchanged.

The PR description now has this Validation section, plus notes on the 340-minute timeout, the phase log and the memory sampler, and still says "Fixes #127".


This summary was automatically extracted from the AI working session output.

@konard

konard commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $39.479171

📊 Context and tokens usage:

Claude Opus 5.5: (15 sub-sessions)

  1. 120.1K / 1M (12%) input tokens, 16.6K / 128K (13%) output tokens
  2. 114.2K / 1M (11%) input tokens, 25.4K / 128K (20%) output tokens
  3. 116.4K / 1M (12%) input tokens, 20.9K / 128K (16%) output tokens
  4. 114.5K / 1M (11%) input tokens, 37.2K / 128K (29%) output tokens
  5. 115.9K / 1M (12%) input tokens, 20.1K / 128K (16%) output tokens
  6. 114.1K / 1M (11%) input tokens, 34.3K / 128K (27%) output tokens
  7. 115.4K / 1M (12%) input tokens, 33.0K / 128K (26%) output tokens
  8. 116.4K / 1M (12%) input tokens, 43.2K / 128K (34%) output tokens
  9. 116.7K / 1M (12%) input tokens, 40.2K / 128K (31%) output tokens
  10. 116.6K / 1M (12%) input tokens, 48.2K / 128K (38%) output tokens
  11. 114.8K / 1M (11%) input tokens, 41.5K / 128K (32%) output tokens
  12. 116.4K / 1M (12%) input tokens, 39.2K / 128K (31%) output tokens
  13. 114.5K / 1M (11%) input tokens, 48.9K / 128K (38%) output tokens
  14. 116.9K / 1M (12%) input tokens, 37.8K / 128K (30%) output tokens
  15. 81.9K / 1M (8%) input tokens, 20.0K / 128K (16%) output tokens

Total: (55.9K new + 1.6M cache writes + 71.3M cache reads) input tokens, 637.9K output tokens, $39.479171 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: opus (claude-opus-5-5)
  • Thinking level: high (~23999 tokens)
  • Model: Claude Opus 5.5 (claude-opus-5-5)

📎 Log file uploaded as Repository (28014KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard

konard commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

🔄 Auto-restart 1/5

Reason: CI failures detected

Evidence:

Starting a new session to address it.

@konard
konard marked this pull request as draft November 26, 2026 01:51
…mpler merge_jobs, a static Tuning property and no optional pragmas parameter
…lpers, the complex method CodeFactor reports at its first-seen lines 273-303
@konard
konard marked this pull request as ready for review November 26, 2026 02:05
@konard

konard commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

Working session summary

Codacy and CodeFactor now pass, along with all 34 other checks on the latest commit (3eca702). The two skipped jobs, publish and auto-merge, are skipped on pull requests by design. main is already merged into the branch, and PR #179 is marked ready for review: #179

Codacy (12 new issues, all from earlier commits in this PR):

  • Docstrings (10 issues): seven multi-line docstrings in scripts/benchmark_report.py and scripts/benchmark_configuration.py were flagged for layout. I couldn't read Codacy's rule settings, so I didn't move the summary to the second line, which might trip the opposite rule. Each is now a one-line docstring, with the details moved into comments. The script's usage text went into a comment block too; --help only ever showed the first line, so its output is the same.
  • C# (2 issues): in csharp/SQLiteVSDoublets/SQLiteStorage.cs, Tuning is now a static read-only property instead of a const. The pragmas constructor parameter is now required instead of optional; every caller already passed it.

CodeFactor (1 complex method): CodeFactor kept showing the message it first recorded at commit 17a6478, the same "Complexity is 18 (lines 273-303)" across every later commit. At that commit, those lines were validate_configuration, not merge_jobs, which is what they point to now. My first fix only simplified merge_jobs, so the check still failed. I then split validate_configuration and three other functions added in this PR (plan, unfinished, provenance) into smaller helpers. Their output is unchanged, and none of the scripts' functions is now above a complexity of 15. The only two at 15 are unchanged from main.

Local checks: the 92 Python tests pass, including the one that requires the committed READMEs to match the generator exactly. ruff, mypy and bandit are clean, and the C# solution builds with no warnings.

No step needs a person to act. I added a "Static analysis" section about these fixes to the PR description. The issue's three requests and the comment about using the latest dependencies were already covered by earlier commits, and there was no new feedback on the issue or the PR.


This summary was automatically extracted from the AI working session output.

@konard

konard commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

🔄 Auto-restart-until-mergeable Log 1/5

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost: $1.619487

📊 Context and tokens usage:

  • 85.4K / 1M (9%) input tokens, 28.4K / 128K (22%) output tokens

Total: (94 new + 68.8K cache writes + 2.5M cache reads) input tokens, 28.4K output tokens, $1.619487 cost

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: opus (claude-opus-5-5)
  • Thinking level: high (~23999 tokens)
  • Model: Claude Opus 5.5 (claude-opus-5-5)

📎 Log file uploaded as Repository (29908KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard

konard commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No uncommitted changes

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

Labels

None yet

Projects

None yet

1 participant