[MUD-Dev2] Persisting a MUD state with plain binary serialization
Jon Mayo
jon.mayo at gmail.com
Tue Feb 3 13:32:14 CET 2009
On Fri, Jan 16, 2009 at 4:51 AM, Tiago <tiago.matias at gmail.com> wrote:
> Hello all!
>
> I'm building a (classical) MUD server as hobby. I would like to have a fully
> persistent game state and thought of using simple serialization to dump the
> entire object graph to disk periodically.
>
> Thing is, binary serialization has a few drawbacks, in terms of versioning
> and it's a pain to control which parts of the graph are serialized or not
> (it's perfect to serialize everything tough).
>
> So, I would like to hear if someone here has had any (bad) experiences with
> serialization (applied to this particular domain) and if they recommend it
> or not.
>
> Thanks!
>
> tiago matias
I just append my binary blobs to the end of a journal file and update
hash table entries to point to the new offset. I write the entire
record out to the journal so book keeping of the blobs is relatively
simple. When I boot and reply the journal I immediately rewrite a
compacted journal to a new file (and rename the old file to a backup).
Compacting can be done as often as you like, but in my system it means
you're writing the entire graph to disk in one go. Which causes a
moderate amount of pausing for players depending on disk performance
and size of the graph.
I keep a generation number in every object, but I don't use it for
anything. It turns out I didn't need it. And accessors for setting all
the fields of an object also set a dirty flag so I know that it needs
to be serialized.
My binary serialization uses a printf style string to describe the
format. It was easier than my other experiments using ASN.1 to
generate routines or doing it by hand with a (large) hand rolled
function for every type of object. I think if I were to do it again
I'd write an XDR parser (as in Sun RPC) and my own code generator, the
printf one was neat in that I could get gcc to warn if I passed the
wrong thing, but with many many fields to dump I either needed a
function that took many arguments or I needed to call the routine and
update an buffer offset each time to do the serialization process.
--
Jon Mayo
<jon.mayo at gmail.com>
More information about the mud-dev2-archive
mailing list