Reputation: 149
I got several report from application users of out of memory exception when connecting to a H2 server. When trying to reproduce, I used jconsole to connect to the H2 server and check what's going on.
I found when I connect to the H2 server and load a database the first time, H2 server start consuming a lot of memory. Before loading any database, the H2 server only consume 3M memory. After using Squirrel SQL client connecting to the H2 and load the 250M file database, H2 server consume about 1G memory. What could be the reason this happen?
H2 server start command: java -Xmx2g -Xms16m -XX:PermSize=16m -XX:MaxPermSize=256m -cp "h2-1.3.173.jar;%H2DRIVERS%;%CLASSPATH%" org.h2.tools.Server -tcp -tcpPort 9097 -tcpAllowOthers -baseDir C:\temp\h2db
My connection string: jdbc:h2:tcp://localhost:9097/db1;DB_CLOSE_DELAY=-1
Additional information: We have quite some tables(1200+) in the database, and 800+ views which union or join on these tables. Will this be the cause of this problem? Could there be any solutions that reduce the memory consumption when loading such database?
Upvotes: 1
Views: 4375
Reputation: 149
After analyzing the heap dump, it's found that most of those memory are occupied by view metadata. For our case, there are 2500+ views, and their metadata occupied 550M heap size. The detail discussion about this can be found here: https://groups.google.com/forum/#!topic/h2-database/4IWPu70yY5U
Thomas acknowledge that the current h2 view metadata should be improved to reduce the memory usage.
Upvotes: 1