Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which embedded DB written in Java for a simple key/value store? [closed]

Tags:

I recently asked a question about Neo4j, which I got working and which seems nice. It's embeddable and it's written in Java and there aren't (too) many dependencies.

However it's a graph DB and I don't know if it's a good idea or not to use it as a simply key/value store.

Basically I've got a big map, which in Java would look like this:

Map<Integer,Map<String,String>>

I've got a few tens of millions of entries in the main map and each entry contains itself a map of property/values. The "inner" map is relatively small: about 20 entries.

I need a way to persist that map from on run of the webapp to the other.

Using Neo4j, what I did is create one node for every ID (integer) and then put one property for each entry inside the inner map. From my early testing it seems to work but I'm not sure it's a good way to proceed.

Which embeddable DB, written in Java, would you use?

The requirements are:

  • written in Java

  • embeddable (so nothing too big)

  • not SQL (*)

  • open source

  • easy to backup (I need to be able to make "live" backups, while the server is running)

My terminology may be a bit wrong too, so feel free to help me / correct me. For my "map of maps", the best fit would be a key/value pair DB right?

I'm a bit lost as the difference between key/value pairs DB, Document DBs, big tables, graph DBs, etc.

I'd also like if it's a good idea to use a graph DB like Neo4J for my need (I think performance really ain't going to be an issue seen the relatively small amount of entries I'll have).

Of course I could simply persist my map of maps myself but I really don't want to reinvent any wheel here. I want to reuse a tried and tested DB...

(*) The reason I do not want SQL is that I'll always have this "map of maps" and that the inner map is going to constantly evolve, so I don't want something too structured.

like image 378
Cedric Martin Avatar asked Mar 19 '12 14:03

Cedric Martin


People also ask

Which type of database is preferred for key-value storage?

Of course, NoSQL encompasses a variety of database types, but easily the most popular is key-value store. This type of data model is built around its extreme simplicity, which allows it to perform blisteringly fast compared to relational databases.

What is the best embedded database for Java?

A few of the dominant providers are H2, HyperSQL, Apache Derby, Berkley DB, Java DB, ObjectDB, and so forth. HyperSQL conforms to the SQL:2011 standard and JDBC 4 specification and supports every classical feature expected from a modern relational database.

What is an embedded key-value store?

Embedded key-value stores come with the additional baggage of embedded systems: they share resources with the system embedding them, which means efficiency is key.

What DB is used for Java?

Java DB. Java DB is Oracle's supported distribution of the open source Apache Derby database. Its ease of use, standards compliance, full feature set, and small footprint make it the ideal database for Java developers. Java DB is written in the Java programming language, providing "write once, run anywhere" portability ...


3 Answers

There seem to be a couple of ports of Google's LevelDB into Java:

  • Dain LevelDB Port (pure Java)
  • Dain LevelDB (JNI)

Then there is a whole list of embedded Java databases here:

  • Embedded java databases
  • Java Embedded Databases Comparison
like image 146
Kiril Avatar answered Oct 21 '22 06:10

Kiril


For your use case I would recommend MapDB (http://www.mapdb.org)

It matches your requirements:

  • written in Java
  • embeddable - single jar with no dependencies
  • not SQL - gives you maps that are persisted to disk
  • open source (Apache 2 licence)
  • easy to backup (few files)

and has other nice features like transactions, concurrency and performance.

like image 22
Andrejs Avatar answered Oct 21 '22 07:10

Andrejs


Chronicle-Map is a new nice player on this field.

  • It is off-heap residing (with ability for being persisted to disk by means of memory-mapped files) Map implementation
  • Super-fast -- sustains millions of queries/updates per second, i. e. each query has sub-microsecond latency on average
  • Supports concurrent updates (assumed to be a drop-in replacement of ConcurrentHashMap)
  • Special support of property maps you mentioned, if the set of properties is fixed within the collection -- allows to update specific properties of the value without any serialization/deserialization of the whole value (20 fields). This feature is called data value generation in Chronicle/Lang project.
  • And many more...
like image 32
leventov Avatar answered Oct 21 '22 07:10

leventov