All,
Working on a custom TCP/IP server for a text-based multiplayer game, using Ruby. Need to find a system for persisting my Ruby objects and am curious for some recommendations.
The server will manage no more than 1GB of data, and since that’s a quite manageable number, I’d love to find a persistence system that allows me to keep everything in memory, and only write it out to disk when I say so (called a “save event” – these are already happening for other unrelated reasons, so I can hook onto these).
Ideally, something with a strong, ActiveRecord-like Ruby interface would be great, with querying/searching, etc.
Some things I have considered.
- MySQL using MEMORY tables (advantages: very familiar with working with it an ActiveRecord, disadvantages: not all of our data is easily represented by relational systems, and I would have to write my own system to save out the tables and re-build them on restart, unless this already exists?)
- MongoDB (advantages: would love to get to know it better, and I think our data is well-suited for a document-based system, disadvantages: not familiar with how it makes use of memory vs disk for storage of data or how I would trigger a ‘persist everything’ event)
- Redis (advantages: seems to have the in-memory model I’m looking for, disadvantages: not familiar with it at all or any of its Ruby interfaces, and not sure how we will be able to translate our data to pure key-values)
I’m guessing there is an elegant solution; MongoDB might well be it, if it heavily utilizes memory in the way I’m describing.
MongoDB uses a memory mapped storage engine and flushes to disk every 60sec by default. You can configure this interval and you can flush any pending writes to disk using the fsync command.
http://www.mongodb.org/display/DOCS/fsync+Command
Using MongoDB with the Mongoid gem might be a good option. Mongoid uses ActiveModel so works very similar to ActiveRecord.