Unexpected heap growth during sustained write transactions despite stable page cache usage
0 reputation · 11 Feb 2022, 00:33 UTC
0 reputation · 11 Feb 2022, 00:33 UTC
The goal is to understand why Neo4j exhibits a steady increase in on‑heap memory while the off‑heap page cache size stays constant during sustained write‑heavy transactions. The environment uses the default dbms.memory.pagecache.size setting (≈50 % of RAM) and exposes JMX metrics such as neo4j.memory.heap.used and neo4j.pagecache.memory.used for observation. Public documentation does not detail how the page cache eviction algorithm treats dirty pages belonging to long‑running, uncommitted transactions, leaving the precise interaction unclear. This uncertainty makes it difficult to predict whether heap growth is a side‑effect of retained transaction state or of delayed page cache eviction.
What eviction policy does Neo4j apply to dirty pages generated by long‑running writes? Does the page cache retain those pages longer than clean pages, causing heap pressure? Are there configurable thresholds or monitoring hooks that can force earlier eviction of dirty pages?
35275 reputation · 11 Feb 2022, 09:50 UTC
The steady increase in on-heap memory during sustained writes is typically caused by the accumulation of **Transaction State**, not a failure of the page cache eviction policy. When writes occur, Neo4j must keep all modified nodes, relationships, and properties in the heap to ensure ACID compliance and isolation until the transaction is committed.
Neo4j uses a Least Recently Used (LRU) eviction policy for the page cache. While the page cache manages data pages read from disk (off-heap), the specific changes made by an active transaction are tracked on-heap.
To address heap growth in heavy write scenarios, follow these steps:
neo4j.memory.transaction.state.used. If this metric scales linearly with your heap, the issue is the transaction duration or size.dbms.memory.heap.max_size is sufficient to hold the peak expected uncommitted transaction state plus the overhead for the query engine.dbms.checkpoint.interval_interval. While checkpoints flush dirty pages to disk, they do not clear the on-heap transaction state of an active session.To provide a more specific recommendation, could you clarify if the heap growth occurs within a single long-running transaction or across thousands of small concurrent transactions?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.