I am working a java application using H2 Database in embedded mode. My Application consumes 150mb of heap memory.
Problem: Steps When I load H2 database with 2 mb of data, database access is fast and heap memory size 160mb.
But When I load H2 database with 30 mb of data(h2 db file size =30 mb). Then accessing the database from my application is very slow. the reason being my application heap size is hugely grown to 300mb of size hence degraded performance. I confirmed using JConsole.
So my understanding is since H2 database is developed using java and since I am using H2 database in embedded mode, the heap size of H2 Database is added to my application which is breaking the application.
The problem is as H2 database size is grown, the performance of my application is degraded.
How to resolve the issue?
I have given the connection as
rurl = "jdbc:h2:file:/" + getDBPath() + dbname + ";CACHE_SIZE=" + (1024 * 1024) + ";PAGE_SIZE=512";
to increase the cache of H2.
In most cases, performance problems are not actually related to the cache size or page size. To analyze performance problems, see the H2 documentation, specially:
If you set the cache size manually to 1024 * 1024, then H2 will use 1 GB heap memory. This setting should only be use if you have a lot more than 1 GB of physical memory available to the JVM (using java -Xmx2048m
or similar). Otherwise, I suggest to use the default settings (16 MB cache size) instead.
Using a smaller page size than the default might decrease performance. This depends on the hard disk, and possibly on the access pattern. However, there is no list of rules when to use a non-default page size - the only way to find out is to try different settings.