Recommend a fast & scalable persistent Map - Java

会有一股神秘感。 提交于 2019-11-28 17:33:07
Michael Lloyd Lee mlk

I'd likely use a local database. Like say Bdb JE or HSQLDB. May I ask what is wrong with this approach? You must have some reason to be looking for alternatives.

In response to comments: As the problem performance and I guess you are already using JDBC to handle this it might be worth trying HSQLB and reading the chapter on Memory and Disk Use.

JDBM3 does exactly what you are looking for. It is a library of disk backed maps with really simple API and high performance.

UPDATE

This project has now evolved into MapDB http://www.mapdb.org

You may want to look into OrientDB.

You can try Java Chronicles from http://openhft.net/products/chronicle-map/ Chronicle Map is a high performance, off-heap, key-value, in memory, persisted data store. It works like a standard java map

As of today I would either use MapDB (file based/backed sync or async) or Hazelcast. On the later you will have to implement you own persistency i.e. backed by a RDBMS by implementing a Java interface. OpenHFT chronicle might be an other option. I am not sure how persistency works there since I never used it, but the claim to have one. OpenHFT is completely off heap and allows partial updates of objects (of primitives) without (de-)serialization, which might be a performance benefit.

NOTE: If you need your map disk based because of memory issues the easiest option is MapDB. Hazelcast could be used as a cache (distributed or not) which allows you to evict elements from heap after time or size. OpenHFT is off heap and could be considered if you only need persistency for jvm restarts.

I've found Tokyo Cabinet to be a simple persistent Hash/Map, and fast to set-up and use.

This abbreviated example, taken from the docs, shows how simple it is to save and retrieve data from a persistent map:

    // create the object
    HDB hdb = new HDB();
    // open the database
    hdb.open("casket.tch", HDB.OWRITER | HDB.OCREAT);
    // add item 
    hdb.put("foo", "hop");
    hdb.close();
David Crawshaw

SQLite does this. I wrote a wrapper for using it from Java: http://zentus.com/sqlitejdbc

As I mentioned in a comment, I have successfully used SQLite with gigabytes of data and tables of hundreds of millions of rows. If you think out the indexing properly, it's very fast.

The only pain is the JDBC interface. Compared to a simple HashMap, it is clunky. I often end up writing a JDBC-wrapper for the specific project, which can add up to a lot of boilerplate code.

JBoss (tree) Cache is a great option. You can use it standalone from JBoss. Very robust, performant, and flexible.

Boris Pavlović

I think Hibernate Shards may easily fulfill all your requirements.

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