Skip to content

Stop a self-hosted server buffering every transaction in memory - #1

Open
abshari wants to merge 1 commit into
mainfrom
fix/self-hosted-sync-table-buffer
Open

abshari wants to merge 1 commit into
mainfrom
fix/self-hosted-sync-table-buffer

Conversation

@abshari

@abshari abshari commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Applies the changes from instantdb#2935 unmodified, to fix the memory growth that makes us restart the self-hosted server.

  • invalidator.clj: fill sync-table-txes only for apps with sync-table subscriptions. Self-hosted servers run as :dev, so every transaction for every app was buffered. The buffer is capped at 10,000 by count, not bytes, so it could fill the heap and stay full while idle.
  • aggregator.clj: cap the sketch cache at 256 entries, overridable with the aggregator-sketch-cache-max-size flag. Each sketch is about 1.6 MB, so the old cap of 4,096 was about 6.5 GB.

Known limitations, accepted as they don't affect us:

  • A sync-table subscription that is still loading can miss transactions. We don't use sync tables: scripted-app has no calls to _syncTableExperimental.
  • Setting the flag to a non-numeric value such as false removes the cache limit. We don't set this flag.

Testing: not compiled or tested yet; the machine this was prepared on has no Clojure toolchain or Postgres. It's also not yet confirmed on the VPS that this is the cause of the restarts.

To verify after deploying, check that these counts stay small while the server is idle:
jcmd <pid> GC.class_histogram | grep -E 'WalEntry|WalRecord'

🤖 Generated with Claude Code

Self-hosted servers run as :dev, so the invalidator kept every
transaction for every app in sync-table-txes. The buffer is capped by
count, not bytes, so it could fill the heap and stay full while idle.
Only buffer for apps with sync-table subscriptions.

Also cap the aggregator sketch cache at 256 entries, overridable with
the aggregator-sketch-cache-max-size flag. Each sketch is about 1.6 MB,
so the old cap of 4096 was about 6.5 GB.

From instantdb#2935.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant