[MUD-Dev] Questions about ... XML as data format

Adam ya_hoo_com at yahoo.com
Fri May 17 22:57:13 New Zealand Standard Time 2002

Kwon Ekstrom <justice at softhome.net> wrote: 
> From: "Ben Chambers" <bjchamb at bellsouth.net>

>> Second question, how plausible is XML as a format for MUD data
>> files as opposed to a SQL based database?  Would it be fast
>> enough using the java classes to parse it to create a XML based
>> format for my MUD data files instead of using SQL?  This idea
>> appeals to me because it makes it easier to write object oriented
>> data files that take into account inheritance and stuff, but I
>> don't know if the load times would be drastically reduced.
> XML works well, you will run into some slowdown during loadup if
> you have large xml files.  SQL is somewhat faster than XML but you
> run into alot of minor problems with design, I haven't looked into
> it too much, but I expect you'll be either doing alot of caching
> and incremental updates, or you'll be doing alot of small searches
> for data.  With XML you'd more than likely load your objects into
> memory at runtime.  Large XML files (I have a social file which I
> imported into my server from resortmud... still need to rid alot
> of the Darryl socials... which takes about 100ms to parse and 2
> seconds to read all the data into Social objects.  There are 593
> socials).
> You'll want to do benchmarks on your own system, I've looked at
> various XML benchmarks and Xerces from Apache.org is the fastest
> (I believe this is what 1.4 ships with, but I haven't tested)
> while JDOM from jdom.org is the easiest to learn (they're real
> objects not interfaces... written specifically to how java works)
> Other than time required, I'd recommend XML.

I'd very very strongly recommend avoiding straightforward XML under
Java as a method for storing server data, for ANY application where
there's likely to be any more than trivial amoutns of data.

E.g., using reasonably up to date version of Zerces (the
IBM-opensourced XML/java parser), time taken to load a 2mb XML file
is heading towards ten minutes on low-end pentiums.

Bear in mind that to store lots of small pieces of data (e.g. the
hitpoints for each of many monsters) imposes massive storage
overhead in XML (one byte of data takes often 100 to store, since
you have to have an open tag, a close tag, and will often choose to
have additional attributes too). Note that this is, of course,
highlt compressible. Note too, that to make a small change to the
file saved on disk essentially requires rewriting the whole file
(XML is not a clever file format designed to make partial rewriting
to a file easy). Som you soon end up automatically splitting your
XML file into many small files, and compressing each one, and then
having buffers to cache reads/writes, and ...

So. You're much better off IMHO going with a database of some sort
to start off with. This is really just an application of an old
maxim that any app which generates/uses/modifies any significant
amount of data should ALWAYS use a database - in case it grows too
large for basic emulation of database features using savefiles.

The only two exceptions I can think of are:

 1. You guarantee the MUD will never have more than 25 players, and
 50 monsters (or an equally small cutoff)

 2. You actually want to experiment with building your own database
 system from the ground up. :).

Or ...

 3. You foolishly forget that prototypes become full products
 against best intentions, and use XML in the prototype, intending to
 replace it with proper DB access routines before using the system -
 and then never get time to take them out, until it gets really
 difficult to remove them, because now your whole DB is stored as
 weakly structured XML.

I did number 3. Whoops.

Adam M
MUD-Dev mailing list
MUD-Dev at kanga.nu

More information about the MUD-Dev mailing list