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

空扰寡人 提交于 2019-12-03 05:46:12

问题


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.


回答1:


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



回答2:


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.




回答3:


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...



回答4:


You could look into berkeley DB

http://docs.oracle.com/cd/E17277_02/html/GettingStartedGuide/index.html

It is quite efficient at dealing with big amount of data and it's key/value. I cannot really tell more about it since I'm discovering it myself but if you have time to take a look into it...




回答5:


Checkout www.jsondb.io

This is a pure java, embeddable lightweight database that stores its data as files which makes it easy to backup




回答6:


You could just stick with an XML or JSON file. Neither of those requires a schema and is fairly easy to go back and forth between disk and memory, especially if performance really doesn't matter too much. (eg. you only load configs every now and then)

The advantage is that XML and JSON are both very simple and deal with Maps pretty well.

You also have a much lighter dependency load on your application. An entire embedded DB-type system is pretty heavy if you are just persisting/un-persisting a big data structure when you need to and not using any of the query or similar capabilities most embedded solutions will add.

To pick off your requirements, it's built in to Java for the most part, easy to back up, since it's just a file, highly embed-able, very much Open Source, and not SQL. XML can be a bit verbose and unwieldy at times, but it's a well-known domain and has very rich tooling surrounding it so that you can deal with it external to your app if needed.




回答7:


Late to the part but you can use Tayzgrid. Its open source and its in-proc cache can be embedded in your application. Its basically an In Memory Data Grid or In Memory Key value store but it has also the capability you want i.e. to be a simple in process embedded key value store.



来源:https://stackoverflow.com/questions/9772058/which-embedded-db-written-in-java-for-a-simple-key-value-store

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