Repository navigation
fix/issues-61-62: Batch the module purge, and set a Go memory limit from the container's - #87
Merged
Merged
Conversation
…othing (#61) An --eager -t push purged each changed module in one transaction, so a large module could exceed the server's transaction memory limit. The purge now runs as CALL { DETACH DELETE } IN TRANSACTIONS OF 5000 ROWS, like the whole-app purge. pruneVanishedModules ran on an eager full push after the whole-app purge had already deleted every Go node of the app, so it never found anything. It is removed, and the stager's end no longer takes the module ids. A live test pins that an eager full push leaves no vanished module. The batched-purge live test needs a database with a per-transaction limit (db.memory.transaction.max=128m) and skips without one.
… per stage (#62) In a container with a cgroup v2 memory limit, cango now sets the Go memory limit to 85 % of it, unless GOMEMLIMIT is set. The GC then collects harder near the limit, instead of letting garbage push the process over it. With no cgroup limit (macOS, a plain host) nothing changes. Under -v, cango logs the live heap, the memory held from the OS and the peak RSS after the analysis, after each Neo4j pass and after the JSON output, so a run's log shows which stage reaches the peak.
rahlk
force-pushed
the
fix/issues-61-62-neo4j-push-memory
branch
from
November 30, 2026 20:31
b716798 to
c95e56b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
tl;dr An
--eager -tpush now deletes a changed module in batches, and in a container cango keeps its heap under 85 % of the container's memory. Gitea's push in a 16 GB container now peaks at 13.8 GiB, down from 15.3 GiB.Motivation and Context
MemoryPoolOutOfMemoryError#61: the Neo4j server refuses a transaction that uses more than its transaction memory limit.Upserts: node and edge batches were already limited to 5,000 rows, and since
--artifact-textuses approximately 5 times the file size in memory #80 a node batch is also sent when its text reaches 16 MiB. I measured the batch size on nats-server with the Neo4j settings from the issue (8G heap,dbms.memory.transaction.total.max=5600m). Every run pushed 1,858,128 nodes and 10,420,173 relationships:The 5,000 row is the second of two runs; the first (494 s) was slower only because it ran first. Larger batches are no faster and use more memory, so the batch size stays at 5,000.
Deletes: the per-module purge of an
--eager -tpush deleted a whole module in one transaction, so a large module could exceed the limit. It now runs asCALL (n) { DETACH DELETE n } IN TRANSACTIONS OF 5000 ROWS, like the whole-app purge of an eager full push already did.pruneVanishedModulesis removed. It ran at the end of an eager full push, after the whole-app purge had already deleted every Go node of the app, and the push writes back only the modules that still exist. It never deleted anything./sys/fs/cgroup/memory.max). AGOMEMLIMITyou set still takes precedence, and nothing changes outside a container.-v, cango logs its memory after the analysis, after the JSON write, and after each Neo4j push pass: live heap, memory from the OS, and peak RSS. The memory test prints these lines.Measurements (
--emit neo4jin a 16 GB container, Neo4j 5.26 with the issue's settings; one run each):mainGitea's memory on this branch, from the new log lines (Go memory limit 13.60 GiB):
Gitea meets the issue's target of 14 GiB, with 0.2 GiB to spare. The peak comes during the second push pass, while the L4 result is still in memory. A more compact L4 result is the next step for more margin, as a follow-up issue.
How Has This Been Tested?
max, a missing or unreadable file, a malformed value, or whenGOMEMLIMITis set;-tags neo4j_it), with the database's per-transaction limit at 128 MiB (NEO4J_db_memory_transaction_max=128m):--eager -tpush purges a module with 60,600 callables, which one transaction cannot delete under that limit;pruneVanishedModulesis gone;-tags memtest) passes on nats-server and gitea, with the results above.go test ./...and golangci-lint pass.Breaking Changes
None. The graph a push writes is unchanged. In a container, Go now collects garbage sooner as the heap nears 85 % of the container's memory.
Types of changes
Checklist
Additional context
DETACH DELETEremoves a node's relationships in the same transaction, so one node with a very large number of relationships can still exceed the limit.docs/design/specs/2026-11-24-neo4j-streaming-push.md(step 5 and §10).MemoryPoolOutOfMemoryError#61. Fixes Reduce analysis memory at -a 4 #62.