Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Collections vs in-memory database performance

I am not sure whether to use Java Collections or some in-memory DB (H2 or HSQLDB - they are probably the fastest). I need a good performance results - there will be hundreds of objects/rows, no JOIN or more complex queries would be performed.

I am really considering in-memory DB, because of limited size of java heap - the objects that I am working with may be quite large and also there will be a lot of them (hundreds as I mentioned)

do you think it is a good idea to use in-memory database for a large amount of data?

like image 931
Igor Avatar asked Feb 14 '12 18:02

Igor


People also ask

Are in memory databases faster?

An in-memory database is a type of database that holds all data in memory rather than using hard drives like traditional databases. Random Access Memory (RAM) is significantly faster than disk and the result is that an in-memory database can read and write data much faster.

Why are in memory databases faster?

In-memory databases are faster than traditional databases because they require fewer CPU instructions. They also eliminate the time it takes to access data from a disk. In-memory databases are more volatile than traditional databases because data is lost when there is a loss of power or the computer's RAM crashes.


2 Answers

Hundreds of 10 KB objects is still only a few MB. Keep it simple is my suggestion. Hundreds of thousands of 1 KB objects will still easily fit into a 32-bit JVM.

I wouldn't use an in memory database until you are getting into the GBs of data. If you have hundreds of GB, your only option is to use a database of some sort.

Disclaimer: I use in memory databases and have even written one or two.

like image 63
Peter Lawrey Avatar answered Oct 06 '22 01:10

Peter Lawrey


Try to do it with collections. If you then realize a problem you can still swich. It is all a matter of abstracting the implementation so your algorithms do not expect one or the other. (Yet another "early-optimization is evil" rant)

like image 45
Bernd Elkemann Avatar answered Oct 06 '22 00:10

Bernd Elkemann