Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In-memory Java DB [closed]

Are there any DBs for Java that can be run in an embedded mode with some tables being stored in-memory while loading others from disk? H2 and JavaDB seem to be the two leaders for Java DBs and I know they both have an in-memory mode, but do they make you load the whole DB into memory or can you decide on a table-by-table basis?

like image 320
Ben McCann Avatar asked Dec 19 '09 07:12

Ben McCann


People also ask

What is in-memory database in Java?

An in-memory database resides completely in main memory, not in the file system. It is useful for testing and developing applications, when you may want to create and discard databases that will never be used again. It is also useful when you need to process only temporary or reproducible data.

Is Derby an in-memory database?

Derby mainly support on-disk database. It also provides in-memory database for testing and developing applications. By following backup procedures, in-memory database can be stored and be used as either an in-memory database or normal on-disk database at a later time.

How do I connect to in-memory database?

In-memory databases can be shared between multiple connections by using Mode=Memory and Cache=Shared in the connection string. The Data Source keyword is used to give the in-memory database a name. Connection strings using the same name will access the same in-memory database.

How does an in-memory database work?

In-memory databases are purpose-built databases that rely primarily on memory for data storage, in contrast to databases that store data on disk or SSDs. In-memory data stores are designed to enable minimal response times by eliminating the need to access disks.


2 Answers

This is the cached table FAQ mentioned in HSQL website.

•Does HSQLDB store all data in memory. Doesn't memory run out as a result?

•It stores all data in memory only if you want to. By default, CREATE TABLE results in a memory table, as this is the best type for smaller tables. For larger tables, use CREATE CACHED TABLE and adjust the cache size to suite your memory use requirements (as little as 8MB or so). See the System Management and Deployment Issues chapter of the Guide. There is no simple rule and no imposition on the part of HSQLDB as maximum flexibility is allowed using only a couple of settings. A popular use of HSQLDB is for OLAP, ETL, and data mining applications where huge Java memory allocations are used to hold millions of rows of data in memory.

I think cached table is already powerful enough to meet your need.

From http://hsqldb.org/web/hsqlFAQ.html

Comparation between cache table and memory table

MEMORY tables and CACHED tables are generally used for data storage. The difference between the two is as follows:

The data for all MEMORY tables is read from the *.script file when the database is started and stored in memory. In contrast the data for cached tables is not read into memory until the table is accessed. Furthermore, only part of the data for each CACHED table is held in memory, allowing tables with more data than can be held in memory.

When the database is shutdown in the normal way, all the data for MEMORY tables is written out to the disk. In comparison, the data in CACHED tables that has changed is written out during operation and at shutdown.

The size and capacity of the data cache for all the CACHED tables is configurable. This makes it possible to allow all the data in CACHED tables to be cached in memory. In this case, speed of access is good, but slightly slower than MEMORY tables.

For normal applications it is recommended that MEMORY tables are used for small amounts of data, leaving CACHED tables for large data sets. For special applications in which speed is paramount and a large amount of free memory is available, MEMORY tables can be used for large tables as well.

It seems this feature is not supported by H2 and Derby(JavaDB) yet. Correct me if it's not the fact.

like image 185
Clark Bao Avatar answered Sep 20 '22 02:09

Clark Bao


Most in-memory databases (such as HSQLDB have ability to cache some (or all) data to disk. Usually it's low enough level so it's transparent to the programmer but certainly is configurable

like image 45
Bostone Avatar answered Sep 19 '22 02:09

Bostone