How to restart Neo4J on Java heap error?

My Neo4J 3.3.4 that is run on AWS EC2 (using Neo4J AMI image) sometimes stalls with this error and becomes nonresponsive:

Jul 16 23:36:38 ip-xxx pre-neo4j.sh[31810]: Caused by: java.lang.OutOfMemoryError: Java heap space
Jul 16 23:36:38 ip-1xxx pre-neo4j.sh[31810]: java.lang.OutOfMemoryError: Java heap space2020-07-16 23:36:38.993+0000 WARN  Error for /db/data/cyphe
Jul 16 23:36:38 ip-xxx pre-neo4j.sh[31810]: java.lang.OutOfMemoryError: Java heap space
Jul 16 23:36:38 ip-xxx pre-neo4j.sh[31810]: java.lang.OutOfMemoryError: Java heap space
Jul 16 23:36:38 ip-xxx pre-neo4j.sh[31810]: java.lang.OutOfMemoryError: Java heap space
Jul 16 23:36:39 ip-xxx pre-neo4j.sh[31810]: 2020-07-16 23:36:39.234+0000 WARN  Error for /db/data/transaction/commit Java heap space
Jul 16 23:36:39 ip-xxx pre-neo4j.sh[31810]: java.lang.OutOfMemoryError: Java heap space

In my neo4j.conf I left all the settings for Java memory, heap and pagecache default (commented out).

I'm currently on t3.medium with 2 vCPUs and 4GB RAM, it is dedicated to Neo4J.

Is there any way to detect this and to restart the database?

Is there any way to manually set the settings based on the config above to avoid that?

You could setup a script which monitors the log for these errors and perform a service neo4j restart when it detects it?

Thank you, Paul, but this seems a bit like a hack. Isn't there a more elegant way to track and resolve this sort of errors? For instance, maybe you have experience with some tool that can be used directly with Neo4J or with Neo4J on AWS that would address the server running out of memory and restart the process?

The elegant way of fixing this is to upgrade and let Neo4J use more memory ;-)

You might want to read https://neo4j.com/developer/kb/understanding-memory-consumption/ and tweak the Java memory settings.

@deemeetree If you need high available you must have a cluster so you could restart. You can run the command "neo4j-admin memrec" and adjust your memory parameters in neo4j.conf.

https://neo4j.com/docs/operations-manual/current/tools/neo4j-admin-memrec/

Thanks

1 Like