tags:

views:

328

answers:

11

I need to store records into a persistant storage and retrieve it on demand. The requirement is as follows -

  1. Extremely fast retrieval and insertion
  2. Each record will have a unique key. This key will be used to retrieve the record
  3. The data stored should be persistent i.e. should be available upon JVM restart
  4. A separate process would move stale records to RDBMS once a day

What do you guys think? I cannot use standard database becuase of latency issues. In memory databases like HSQLDB / H2 has performace contraints. Moreover the records are simple string objects and do not qualify for SQL. I am thinking of some kind of flat file based solution. Any ideas? Any open source project? I am sure, there must be someone who has solved this problem before :)

+1  A: 

MySQL with shards may be a good idea. However, it depends on what is the data volume, transactions per second and latency you need.

In memory databases are also a good idea. In fact MySQL provides memory-based tables as well.

Shantanu Kumar
yeah...in memory databases are good...but my previous experience with HSQLDB is not so great...in fact we had determined HQSQL db was taking substantial time in our processing...Not sure about MSQL though
AAK
A: 

Have you actually proved that using an out-of-process SQL database like MySQL or SQL Server is too slow, or is this an assumption?

You could use a SQL database approach in conjunction with an in-memory cache to ensure that retrievals do not hit the database at all. Despite the fact that the records are plaintext I would still advise using SQL over a flat file solution (e.g. using a text column in your table schema) as the RDBMS will perform optimisations that a file system cannot (e.g. caching recently accessed pages, etc).

However, without more information about your access patterns, expected throughput, etc. I can't provide much more in the way of suggestions.

Adamski
Yes. Our legacy system uses RDBMS and it takes few milliseconds for retrieval of data. This is high frequency application, the speed required in sub millisecond for whole message processing where storage and retrieval are just one part of the message processing
AAK
More importantly, what are your access patterns? Is the data sequential (e.g. time series)? Is the data written once and read many times, or can be potentially be updated? There are bespoke solutions for this (e.g. KDB) but it largely depends on your use case.
Adamski
A: 

Will all the records and keys you need fit in memory at once? If so, you could just use a HashMap<String,String>, since it's Serializable.

wdebeaum
-1 from me. You'll need to manually serialize the entire HashMap on each insert, which is obviously very slow.
Outlaw Programmer
yep...but how about real time data persistence? I need to persist data as it comes so that if the JVM crashes I do not lose the data...
AAK
@AAK: you could just serialize and store each change. Then you don't have a immediately usable persistence storage, but have a log from which you can rebuild the storage in the event of an error.
Joachim Sauer
(btw, I'm not saying that this is the ideal soluton, I'm just saying that it could be made to work)
Joachim Sauer
A: 

How much does it matter if you lose a record or two? Where are they coming from? Do you have a transactional relationship with the source?

If you have serious reliability requirements then I think you may need to be prepared to pay some DB Overhead.

Perhaps you could separate the persistence problem from the in-memory problem. Use a pup-sub approach. One subscriber look after in-memory, the other persisting the data ready for subsequent startup?

Distributed cahcing products such as WebSphere eXtreme Scale (no JEE dependency) might be relevent if you can buy rather than build.

djna
The reliability requirements are pretty high. I was also inclined towards some caching solution. EHCache?
AAK
+4  A: 

Have a look at LinkedIn's Voldemort.

fvu
wow...this looks promising...
AAK
No, it doesn't. Sub ms?
Stephan Eggermont
A: 

How bad would it be if you lose a couple of entries in case of a crash?

If it isn't that bad the following approach might work for you:

Create flat files for each entry, name of file equals id. Possible one file for a not so big number of consecutive entries.

Make sure your controller has a good cache and/or use one of the existing caches implemented in Java.

Talk to a file system expert how to make this really fast

It is simple and it might be fast. Of course you lose transactions including the ACID principles.

Jens Schauder
The reliability requirements are pretty high. We cannot afford to lose any data upon crash...
AAK
+1  A: 

If all the data fits in memory, MySQL can run in memory instead of from disk (MySQL Cluster, Hybrid Storage). It can then handle storing itself to disk for you.

Dean J
A: 

If you are looking for a simple key-value store and don't need complex sql querying, Berkeley DB might be worth a look.

Another alternative is Tokyo Cabinet, a modern DBM implementation.

Peter Hoffmann
A: 

Would a Tuple space / JavaSpace work? Also check out other enterprise data fabrics like Oracle Coherence and Gemstone.

Kevin
+1  A: 

What about something like CouchDB?

Mark
A: 

Sub millisecond r/w means you cannot depend on disk, and you have to be careful about network latency. Just forget about standard SQL based solutions, main-memory or not. In a ms, you cannot get more than 100 KByte over a GBit network. Ask a telecom engineer, they are used to solving these kind of problems.

Stephan Eggermont