views:

287

answers:

3
+1  Q: 

In Memory Database

I'm using SqlServer to drive a WPF application, I'm currently using NHibernate and pre-read all the data so it's cached for performance reasons. That works for a single client app, but I was wondering if there's an in memory database that I could use so I can share the information across multiple apps on the same machine. Ideally this would sit below my NHibernate stack, so my code wouldn't have to change. Effectively I'm looking to move my DB from it's traditional format on the server to be an in memory DB on the client.

Note I only need select functionality.

A: 

http://www.db4o.com/ can be your friend!

Fox
A: 

Velocity is an out of process object caching server designed by Microsoft to do pretty much what you want although it's only in CTP form at the moment.

I believe there are also wrappers for memcached, which can also be used to cache objects.

Matthew Steeples
+1  A: 

I would be incredibly surprised if you even need to load all your information in memory. I say this because, just as one example, I'm working on a Web app at the moment that (for various reasons) loads thousands of records on many pages. This is PHP + MySQL. And even so it can do it and render a page in well under 100ms.

Before you go down this route make sure that you have to. First make your database as performant as possible. Now obviously this includes things like having appropriate indexes and tuning your database but even though are putting the horse before the cart.

First and foremost you need to make sure you have a good relational data model: one that lends itself to performant queries. This is as much art as it is science.

Also, you may like NHibernate but ORMs are not always the best choice. There are some corner cases, for example, that hand-coded SQL will be vastly superior in.

Now assuming you have a good data model and assuming you've then optimized your indexes and database parameters and then you've properly configured NHibernate, then and only then should you consider storing data in memory if and only if performance is still an issue.

To put this in perspective, the only times I've needed to do this are on systems that need to perform millions of transactions per day.

One reason to avoid in-memory caching is because it adds a lot of complexity. You have to deal with issues like cache expiry, independent updates to the underlying data store, whether you use synchronous or asynchronous updates, how you give the client a consistent (if not up-to-date) view of your data, how you deal with failover and replication and so on. There is a huge complexity cost to be paid.

Assuming you've done all the above and you still need it, it sounds to me like what you need is a cache or grid solution. Here is an overview of Java grid/cluster solutions but many of them (eg Coherence, memcached) apply to .Net as well. Another choice for .Net is Velocity.

It needs to be pointed out and stressed that something like NHibernate is only consistent so long as nothing externally updates the database and that there is exactly one NHibernate-enabled process (barring clustered solutions). If two desktop apps on two different PCs are both updating the same database with NHibernate the caching simply won't work because the persistence units simply won't be aware of the changes the other is making.

cletus
be surprised, be very surprised, lots of data + animations = video output, I need all the speed I can get.
MrTelly
Oh it's certainly not impossible, just improbable. In my experience. So you might need in memory caching. If the cached data is updated and those updates need to propagate then multiple instances of NHibernate won't work (clustering notwithstanding).
cletus