Frequent "java.lang.OutOfMemoryError: Java heap space" errors
-
I'm getting errors about the Java heap space fairly regularly (see sample below). They appear to take the Metabase app down. I had previously pushed the memory up on <my cloudron>/#/app/d00ef8b7-e3a6-43e3-8c3c-73d822c1fded/resources to 3GB but the container doesn't appear to hit that. A quick scan of Metabase docs seems to indicate there's an assumption the JVM will sensibly allocate memory but I'm wondering if it's not doing that under Docker operating conditions? I can't see an obvious way of passing in a Java option to explicitly set the heap size. Anyone else hit an issue like this? (I don't think I'm running anything too heavy in Metabase)
2020-11-02T16:02:01.000Z 2020-11-02 16:01:56,367 WARN strategy.EatWhatYouKill ::
2020-11-02T16:02:01.000Z java.lang.OutOfMemoryError: Java heap space
2020-11-02T16:02:01.000Z Exception in thread "MetabaseScheduler_QuartzSchedulerThread" java.lang.OutOfMemoryError: Java heap space
2020-11-02T16:02:01.000Z 2020-11-02 16:02:01,028 WARN io.ManagedSelector :: java.lang.OutOfMemoryError: Java heap space
2020-11-02T16:02:01.000Z 2020-11-02 16:02:01,089 ERROR sync.util :: Error fingerprinting Table 8 'hars'
2020-11-02T16:02:01.000Z org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
2020-11-02T16:02:01.000Z at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:337) ~[metabase.jar:?]
2020-11-02T16:02:01.000Z at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:446) ~[metabase.jar:?]
2020-11-02T16:02:01.000Z at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:370) ~[metabase.jar:?]
2020-11-02T16:02:01.000Z at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:149) ~[metabase.jar:?] -
@jamesgallagher I have fixed the package to set the heap size. It was also recommended in the upstream docs - https://www.metabase.com/docs/latest/troubleshooting-guide/running.html
-
Thanks for looking into this and apologies for not following up - need to check my notification settings. (also work has been really busy so no mental energy for looking at my outside interests!)
-
Usually, this error is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.
Therefore you pretty much have two options:
-
Increase the default memory your program is allowed to use using the -Xmx option (for instance for 1024 MB: -Xmx1024m)
-
Modify your program so that it needs less memory, using less big data structures and getting rid of objects that are not any more used at some point in your program
Increasing the heap sizeis a bad solution, 100% temporary. It will crash again in somewhere else. To avoid these issues, write high performance code:
- Use local variables wherever possible.
- Make sure you select the correct object (EX: Selection between String, StringBuffer and StringBuilder)
- Use a good code system for your program(EX: Using static variables VS non static variables)
- Other stuff which could work on your code.
- Try to move with Multy Threading
-