1998Q2/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: [MUD&#45;Dev] Persistant storage.... My current idea. -->
<!--X-From-R13: X Q Znjerapr <pynjNhaqre.rate.ftv.pbz> -->
<!--X-Date: Fri, 03 Apr 1998 23:42:18 +0000 -->
<!--X-Message-Id: 199804032342.PAA49609#under,engr.sgi.com -->
<!--X-Content-Type: text/plain -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, [MUD-Dev] Persistant storage.... My current idea.</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:claw#under,engr.sgi.com">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00010.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00012.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00063.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00012.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00011">Author</A>
&nbsp;|&nbsp;<A HREF="#00011">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00011">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>[MUD-Dev] Persistant storage.... My current idea.</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#null,net">mud-dev#null,net</A></LI>
<LI><em>Subject</em>: [MUD-Dev] Persistant storage.... My current idea. </LI>
<LI><em>From</em>: J C Lawrence &lt;<A HREF="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</A>&gt;</LI>
<LI><em>Date</em>: Fri, 03 Apr 1998 15:42:11 -0800</LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>

Forwarded to the list for Cynbe:

Date: Fri, 3 Apr 1998 17:45:22 -0600
From: Cynbe ru Taren &lt;cynbe#muq,org&gt;
Subject: [MUD-Dev] Persistant storage.... My current idea. 

| &gt; On Wed, 1 Apr 1998, J C Lawrence wrote:
| &gt;&gt; A very simple cheat which performs very nicely is to do something
| &gt;&gt; as follows:
| &gt;&gt; 
| &gt;&gt; Every record in the DB is identified by a unique record # of a
| &gt;&gt; signed integer type.
| &gt;&gt; 
| &gt;&gt; The DB consists of two files, the database itself, and an index.
| &gt;&gt; 
| &gt;&gt; The index file is an array of the following structures:
| &gt;&gt; 
| &gt;&gt;   struct { 
| &gt;&gt;     off_t record_pos; // Offset of the record in the DB 
| &gt;&gt;     size_t record_len; // Length of the record in the DB 
| &gt;&gt;   }
| &gt;&gt;
| &gt; I still see no reason to store the index on disk.  

Just a quick note, and sorry if I keep harping on Muq -- it just
so happens that after five solid years of working on it spare-time,
I know it better than I do other systems. :)

In Muq (<A  HREF="http://muq.org/~cynbe/muq.html">http://muq.org/~cynbe/muq.html</A>) I've done a fairly carefully
performance-tuned module vm.t which is designed to be usable with
other systems (i.e., it isn't inextricably linked with all my other
Muq code/modules) along the above sorts of lines:

Every object is identifed by an abstract pointer.

(Originally, this was a 32-pointer, currently I've moved to 64-bit
pointers using gcc's "long long" support, but this is selectable by
changing a single #define.)

This abstract pointer is in fact an integer containing two bitfields:
one specifies the object's size to the nearest power of two.

For each size octave, I maintain a db file which is essentially an
array of records of that size.

Another bitfield in the abstract pointer gives the offset of the
record in question within the relevant file.

The encoding I use actually allocates bigger offset fields to the
smaller octaves, since one is more likely to have (say) 1,000,000
8-byte objects in a system than 1,000,000 1-megabyte objects. This
is pretty important in the 32-bit implementation, less so in the
64-bit implementation.

The resulting design lets me read any object in the db into memory
in -exactly- one read(), which is pretty much provably optimal, and
likely to be at least twice the performance of many index-file based
designs.  (A factor of two in disk access speed just might matter to
some people... :)

Meanwhile, I keep a cache buffer in ram of recently accessed objects:
I'm not comfortable with the time and space overhead of LRU management,
so instead I manage them essentially as a FIFO queue that objects
cycle through once loaded into cache:  They are loaded at one end
and deleted at the other.  Since deleted objects will still be in the
OS file system cache in general, frequently used objects will get
'read' back in very quickly, giving (I hope, no performance studies
yet) much of the performance of an LRU system in practice, without
much of the overhead.

I allocate a (very) carefully tuned hashtable about 1/8 the size of
the ram buffer to map abstract pointers to current addresses: This
mapping takes about 15 risc cycles, which may sound like a lot
compared to single-cycle access via a hard pointer, but (given a
little intelligent coding, like looking up a string address just
once when copying it, not once per byte) turns out according to gprof
to be consuming only about 5% of my CPU time when Muq is running: I
feel this is a very reasonable price to pay for disk-based
operation...

 Cynbe

-- 
J C Lawrence                               Internet: claw#null,net
(Contractor)                               Internet: coder#ibm,net
---------(*)                     Internet: claw#under,engr.sgi.com
...Honourary Member of Clan McFud -- Teamer's Avenging Monolith...

</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<ul compact><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><A NAME="00012" HREF="msg00012.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>
<ul compact><li><em>From:</em> J C Lawrence &lt;claw#under,engr.sgi.com&gt;</li></ul>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00010.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00012.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00063.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00012.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00011"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00011"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><STRONG>Re: [MUD-Dev] Persistant storage.... My current idea.</STRONG>, <EM>(continued)</EM>
<ul compact>
<ul compact>
<LI><strong><A NAME="00010" HREF="msg00010.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Fri 03 Apr 1998, 17:57 GMT
<UL>
<LI><strong><A NAME="00013" HREF="msg00013.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Sat 04 Apr 1998, 01:32 GMT
<UL>
<LI><strong><A NAME="00049" HREF="msg00049.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Tue 07 Apr 1998, 16:56 GMT
<UL>
<LI><strong><A NAME="00063" HREF="msg00063.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Wed 08 Apr 1998, 00:50 GMT
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</ul>
<LI><strong><A NAME="00011" HREF="msg00011.html">[MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Fri 03 Apr 1998, 23:42 GMT
<UL>
<LI><strong><A NAME="00012" HREF="msg00012.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Sat 04 Apr 1998, 00:04 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00018" HREF="msg00018.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Sat 04 Apr 1998, 23:21 GMT
</LI>
<LI><strong><A NAME="00019" HREF="msg00019.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Sat 04 Apr 1998, 23:21 GMT
<UL>
<LI><strong><A NAME="00022" HREF="msg00022.html">Re: [MUD-Dev] Persistant storage.... My current idea.</A></strong>, 
Ben Greear <a href="mailto:greear#cyberhighway,net">greear#cyberhighway,net</a>, Sun 05 Apr 1998, 02:02 GMT
</LI>
</UL>
</LI>
</ul>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>