Performance issues using H2 DB in embedded mode with heavy load of data in database

风格不统一 提交于 2019-12-20 10:47:13

问题


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.


回答1:


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:

  • Database Performance Tuning
  • Using the Built-In Profiler
  • Application Profiling
  • Database Profiling
  • Statement Execution Plans
  • How Data is Stored and How Indexes Work

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.



来源:https://stackoverflow.com/questions/9798896/performance-issues-using-h2-db-in-embedded-mode-with-heavy-load-of-data-in-datab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!