1998Q1/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: request for comments (was: Mud&#45;Dev FAQ) -->
<!--X-From-R13: f001tzhNabin.jevtug.rqh -->
<!--X-Date: Thu, 08 Jan 1998 16:43:30 +0000 -->
<!--X-Message-Id: Pine.PMDF.3.95.980108113739.543180857A&#45;100000#nova,wright.edu -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: 34B0EEF3.5EC5402C#4cs,com -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, request for comments (was: Mud-Dev FAQ)</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:s001gmu#nova,wright.edu">
</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="msg00116.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00118.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00223.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00122.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00117">Author</A>
&nbsp;|&nbsp;<A HREF="#00117">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00117">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>request for comments (was: Mud-Dev FAQ)</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>: request for comments (was: Mud-Dev FAQ)</LI>
<LI><em>From</em>: <A HREF="mailto:s001gmu#nova,wright.edu">s001gmu#nova,wright.edu</A></LI>
<LI><em>Date</em>: Thu, 08 Jan 1998 11:44:01 -0500 (EST)</LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>


On Mon, 5 Jan 1998, Vadim Tkachenko wrote:
&gt;
&gt;Jon A. Lambert wrote:

...

&gt;&gt;  Variations on event-driven design
&gt;
&gt;Can you please elaborate on that?

I've spent the last month or so of my free time tossing around ideas for our
event driver, and I think I've finally settled on a general model.  I have yet
to implement and test all of it, so I'm sure I'll be fine-tuning it, but here's
where it stands for the moment:

  Definately Multi-threaded, though not as heavily as JC's model (so far).
  I'm aiming for a statically sized pool of about 10 threads to handle events,
  though that number is most certainly not set in stone.

  All events are descended from a base event class, and the driver has
  knowledge of only that base class.  (A fundamental of OO design, but worth
  stating.)

  Pending events are stored in a queue wrapped in a pretty simple structure
  containing a reference to the event object, an event ID, and the event's
  timestamp (along with all the stuff necessary to make a doubly linked list).
  Call it a Tuple if you like.

  Each 'tick', all events scheduled to be handled are pulled off the main
  queue into a secondary queue, where the thread pool attacks them (in no
  guaranteed order), each thread grabbing an event and calling it's Handle
  method.  Threads go back to sleep once all events in the secondary queue
  have been handled.

  I will most likely use a locked model for access to the DB, but I need to
  do a bit -o- research and thinking before I commit to one model or the other.

The main design concerns I dealt with in comming to the decisions I've made:

  How many threads, executing potentially I/O intensive DB Queries, can run
  simultaineously w/o bogging down the server?  This is obviously tied to
  the machine/os/thread implementation/DB version the end design is run on,
  but for my sanity I decided on a static pool, with a boot-time configurable
  number of threads.  heck, I could prolly pretty easily add a command to
  allow admin to add some threads to the pool on the fly, but I prefer to
  minimize the cost of thread creation, localizing it to a boot-time expense.

  For the lockless v. locked model, my main concern was/is how many threads,
  executing at the same tick, are going to be handling events targeting the 
  same data?  I figgure there won't be too many events executed simultaineously
  that target the same data.  It will happen, there's no doubt about that, but
  I feel the majority of events (executing at the same tick) will be aimed at
  different targets.  This assumption may well be proven wrong, but for now I
  can only go with it and see what happens.  :)   If it proves to be the case
  that a large enough % of the events target the same data, I may adopt some
  schemes to try and shuffle events targeting the same data into the same
  threads, so they are executed sequentially by that thread, removing the
  issue.

  My reasoning is that, combined with ballancing the number of threads
  correctly, this will allow the overhead of locking data to be outweighed
  by the preformance gain of multithreading.  Too much locking, and the
  threads execute in series, loosing all preformance increase, too few
  threads, and locking overhead outweighs performance gain.

Current, unanswered questions:

  What happens if it takes more than one tick to process all the events in
  the secondary queue?  This says either that there are not enough threads to
  process all the events quickly enough, or that there are too many events! :)
  I'm thinking I'll just put the events in the same secondary queue, and have
  the threads do a bit of prioritizing... only if there are no threads
  executing events for the previous tick will they start processing the new 
  tick's events...  dunno.  I need to think about it some more.  :)

  I haven't spent much time on gracefull shut-down of the queue, or storing of
  the event list to rebuild a queue, but they are next on the hit parade.

Did I miss anything glaring? :)

-Greg


</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="00167" HREF="msg00167.html">Re: [MUD-Dev] request for comments (was: Mud-Dev FAQ)</A></strong>
<ul compact><li><em>From:</em> JC Lawrence &lt;claw#under,Eng.Sun.COM&gt;</li></ul>
<li><strong><A NAME="00122" HREF="msg00122.html">Re: [MUD-Dev]  Event handling (was: request for comments)</A></strong>
<ul compact><li><em>From:</em> Vadim Tkachenko &lt;vadimt#4cs,com&gt;</li></ul>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<UL><LI><STRONG>References</STRONG>:
<UL>
<LI><STRONG><A NAME="00026" HREF="msg00026.html">Re: [MUD-Dev]  request for comments (was: Mud-Dev FAQ)</A></STRONG>
<UL><LI><EM>From:</EM> Vadim Tkachenko &lt;vadimt#4cs,com&gt;</LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00116.html">Re: [MUD-Dev] Commercial value of RP</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00118.html">Re: [MUD-Dev]  MUD Economy</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00223.html">[MUD-Dev] Event Handling</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00122.html">Re: [MUD-Dev]  Event handling (was: request for comments)</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00117"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00117"><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]  request for comments (was: Mud-Dev FAQ)</STRONG>, <EM>(continued)</EM>
<ul compact>
<ul compact>
<ul compact>
<LI><strong><A NAME="00033" HREF="msg00033.html">Re: [MUD-Dev]  request for comments (was: Mud-Dev FAQ)</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Mon 05 Jan 1998, 21:05 GMT
</LI>
<LI><strong><A NAME="00050" HREF="msg00050.html">Re: [MUD-Dev]  request for comments (was: Mud-Dev FAQ)</A></strong>, 
coder <a href="mailto:coder#ibm,net">coder#ibm,net</a>, Tue 06 Jan 1998, 05:32 GMT
</LI>
<LI><strong><A NAME="00078" HREF="msg00078.html">Re: [MUD-Dev] request for comments (was: Mud-Dev FAQ)</A></strong>, 
JC Lawrence <a href="mailto:claw#under,Eng.Sun.COM">claw#under,Eng.Sun.COM</a>, Wed 07 Jan 1998, 00:52 GMT
<UL>
<LI><strong><A NAME="00223" HREF="msg00223.html">[MUD-Dev] Event Handling</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Tue 13 Jan 1998, 03:35 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00117" HREF="msg00117.html">request for comments (was: Mud-Dev FAQ)</A></strong>, 
s001gmu <a href="mailto:s001gmu#nova,wright.edu">s001gmu#nova,wright.edu</a>, Thu 08 Jan 1998, 16:43 GMT
<UL>
<LI><strong><A NAME="00122" HREF="msg00122.html">Re: [MUD-Dev]  Event handling (was: request for comments)</A></strong>, 
Vadim Tkachenko <a href="mailto:vadimt#4cs,com">vadimt#4cs,com</a>, Thu 08 Jan 1998, 20:13 GMT
<UL>
<LI><strong><A NAME="00141" HREF="msg00141.html">Event handling (was: request for comments)</A></strong>, 
s001gmu <a href="mailto:s001gmu#nova,wright.edu">s001gmu#nova,wright.edu</a>, Fri 09 Jan 1998, 16:11 GMT
<UL>
<LI><strong><A NAME="00144" HREF="msg00144.html">Re: [MUD-Dev]  Event handling</A></strong>, 
Shawn Halpenny <a href="mailto:malachai#iname,com">malachai#iname,com</a>, Fri 09 Jan 1998, 17:50 GMT
<UL>
<LI><strong><A NAME="00147" HREF="msg00147.html">Re: [MUD-Dev]  Event handling</A></strong>, 
Vadim Tkachenko <a href="mailto:vadimt#4cs,com">vadimt#4cs,com</a>, Fri 09 Jan 1998, 19:02 GMT
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</ul>
</ul>
</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>