I am currently calculating memory usage in my Neo4j database manually by adding data, running CALL db.checkpoint()
, shutting down the database, and checking the database file in the data/databases/neo4j
directory. I then count the file size by hand. However, this process is very slow, especially when I need to measure memory usage multiple times.
I came across this question where it's mentioned that the storage size for a node is 14 bytes, a relationship is 33 bytes, and a property is 41 bytes.
Is there a more efficient way to calculate memory usage in Neo4j based on the number of nodes, relationships, and properties without needing to rely on this manual approach? Can I use the mentioned byte sizes as an estimate for quick calculations?
My Java code:
@Override
public long getDatabaseSize(Transaction transaction) {
String query = "CALL dbms.queryJmx('neo4j.metrics:name=neo4j.database.neo4j.store.size.total')";
try (Result result = transaction.execute(query)) {
// TODO: end this block
} catch (Exception e) {
throw new RuntimeException("Failed to retrieve database size: ", e);
}
return -1;
}
You can get storage size metrics with the following procedure :
Replace <mydb>
with the name of your database :
CALL dbms.queryJmx('neo4j.metrics:name=neo4j.database.<mydb>.store.size.total')
╒══════════════════════════════════════════════════════════════╤══════════════════════════════════════════════════════╤══════════════════════════════════════════════════════════════════════╕
│name │description │attributes │
╞══════════════════════════════════════════════════════════════╪══════════════════════════════════════════════════════╪══════════════════════════════════════════════════════════════════════╡
│"neo4j.metrics:name=neo4j.database.docslogin.store.size.total"│"Information on the management interface of the MBean"│{Value: {description: "Attribute exposed for management", value: 15430│
│ │ │044}, Number: {description: "Attribute exposed for management", value:│
│ │ │ 15430044}} │
└──────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────┘