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.
Features of H2 DatabaseIt is an extremely fast database engine. H2 is open source and written in Java. It supports standard SQL and JDBC API. It can use PostgreSQL ODBC driver too.
H2 is an embedded, open-source, and in-memory database. It is a relational database management system written in Java.
Persist the data in H2 Database If we want to persist the data in the H2 database, we should store data in a file. To achieve the same, we need to change the datasource URL property. In the above property, the sampledata is a file name.
Mainly, H2 database can be configured to run as inmemory database, which means that data will not persist on the disk. Because of embedded database it is not used for production development, but mostly used for development and testing.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With