哪个嵌入式数据库用 Java 编写,用于简单的键/值存储?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9772058/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which embedded DB written in Java for a simple key/value store?
提问by Cedric Martin
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.
我最近问了一个关于 Neo4j 的问题,我开始工作了,看起来不错。它是可嵌入的,并且是用 Java 编写的,并且没有(太多)依赖项。
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:
基本上我有一张大地图,在 Java 中看起来像这样:
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.
我在主映射中有几千万个条目,每个条目都包含一个属性/值映射。“内部”地图相对较小:大约 20 个条目。
I need a way to persist that map from on run of the webapp to the other.
我需要一种方法来将该地图从 web 应用程序的运行保存到另一个。
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.
使用 Neo4j,我所做的是为每个 ID(整数)创建一个节点,然后为内部映射中的每个条目放置一个属性。从我的早期测试来看,它似乎有效,但我不确定这是一个很好的方法。
Which embeddable DB, written in Java, would you use?
您会使用哪个用 Java 编写的嵌入式数据库?
The requirements are:
要求是:
written in Java
embeddable (so nothing too big)
notSQL (*)
open source
easy to backup (I need to be able to make "live" backups, while the server is running)
用Java编写
可嵌入(所以没什么太大的)
不是SQL (*)
开源
易于备份(我需要能够在服务器运行时进行“实时”备份)
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).
我还想使用像 Neo4J 这样的图形数据库来满足我的需要是否是个好主意(我认为性能真的不会成为问题,因为我将拥有相对少量的条目)。
Of course I couldsimply 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.
(*) 我不想要 SQL 的原因是我将永远拥有这个“地图地图”并且内部地图会不断发展,所以我不想要过于结构化的东西。
回答by Eric C.
You could look into berkeley DB
你可以看看伯克利数据库
http://docs.oracle.com/cd/E17277_02/html/GettingStartedGuide/index.html
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...
它在处理大量数据及其键/值方面非常有效。由于我自己发现了它,因此我无法详细介绍它,但是如果您有时间研究它......
回答by Kiril
There seem to be a couple of ports of Google's LevelDBinto Java:
似乎有几个 Google 的LevelDB 移植到 Java 中:
Then there is a whole list of embedded Java databases here:
然后这里有一个完整的嵌入式 Java 数据库列表:
回答by cdeszaq
You couldjust stick with an XML or JSON file. Neither of those requiresa 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)
您可以坚持使用 XML 或 JSON 文件。这些都不需要模式,并且在磁盘和内存之间来回切换相当容易,尤其是在性能真的不太重要的情况下。(例如,您只时不时地加载配置)
The advantage is that XML and JSON are both very simple and deal with Maps pretty well.
优点是 XML 和 JSON 都非常简单,并且可以很好地处理 Maps。
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.
您对应用程序的依赖负载也轻得多。如果您只是在需要时持久化/取消持久化大数据结构并且不使用大多数嵌入式解决方案将添加的任何查询或类似功能,那么整个嵌入式 DB 类型系统会非常繁重。
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.
为了满足您的需求,它大部分内置于 Java 中,易于备份,因为它只是一个文件,高度可嵌入,非常开源,而不是 SQL。XML 有时可能有点冗长和笨拙,但它是一个众所周知的域,并且有非常丰富的工具围绕它,因此您可以在需要时在应用程序外部处理它。
回答by Andrejs
For your use case I would recommend MapDB(http://www.mapdb.org)
对于您的用例,我会推荐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)
- 用Java编写
- embeddable - 没有依赖的单个 jar
- 不是 SQL - 为您提供持久保存到磁盘的映射
- 开源(Apache 2 许可证)
- 易于备份(文件少)
and has other nice features like transactions, concurrency and performance.
并具有其他不错的功能,例如事务、并发性和性能。
回答by leventov
Chronicle-Map
is a new nice player on this field.
Chronicle-Map
是这个领域的新好球员。
- 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 mapsyou 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 generationin Chronicle/Langproject.
- And many more...
- 它是堆外驻留的(能够通过内存映射文件持久化到磁盘)
Map
实现 - 超快——每秒维持数百万次查询/更新,即每个查询平均有亚微秒的延迟
- 支持并发更新(假设是 的直接替换
ConcurrentHashMap
) - 对您提到的属性映射的特殊支持,如果属性集在集合中是固定的 - 允许更新值的特定属性,而无需对整个值(20 个字段)进行任何序列化/反序列化。此功能在 Chronicle/ Lang项目中称为数据值生成。
- 还有很多...
回答by Basit Anwer
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 storebut it has also the capability you want i.e. to be a simple in process embedded key value store.
迟到了,但您可以使用 Tayzgrid。它的开源及其进程内缓存可以嵌入到您的应用程序中。它基本上是一个内存数据网格或内存键值存储,但它也具有您想要的功能,即成为一个简单的进程内嵌入键值存储。
回答by Farooq Khan
Checkout www.jsondb.io
结帐 www.jsondb.io
This is a pure java, embeddable lightweight database that stores its data as files which makes it easy to backup
这是一个纯 Java 的、可嵌入的轻量级数据库,将其数据存储为文件,便于备份