msg00297.html

1999Q2/msg00297.html · 8.1 KB

From the archive 1999Q2.zip

Download the archive   « Back to the archive contents

<!-- MHonArc v2.4.4 -->
<!--X-Subject: Re: [MUD&#45;Dev] Multi&#45;threaded mud server. -->
<!--X-From-R13: [nex Uevggre <znexNreqbf.Egnasbeq.SRG> -->
<!--X-Date: Mon, 17 May 1999 23:43:23 &#45;0700 -->
<!--X-Message-Id: 199905171953.MAA11617#erdos,Stanford.EDU -->
<!--X-Content-Type: text -->
<!--X-Reference: 4.1.19990516221449.00a59c40#pop,darklock.com -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, Re: [MUD-Dev] Multi-threaded mud server.</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:mark#erdos,Stanford.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="msg00296.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00298.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00282.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00299.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00297">Author</A>
&nbsp;|&nbsp;<A HREF="#00297">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00297">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>Re: [MUD-Dev] Multi-threaded mud server.</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Subject</em>: Re: [MUD-Dev] Multi-threaded mud server.</LI>
<LI><em>From</em>: Mark Gritter &lt;<A HREF="mailto:mark#erdos,Stanford.EDU">mark#erdos,Stanford.EDU</A>&gt;</LI>
<LI><em>Date</em>: Mon, 17 May 1999 12:53:43 -0700 (PDT)</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Sender</em>: <A HREF="mailto:mud-dev-admin#kanga,nu">mud-dev-admin#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
Caliban Tiresias Darklock writes:
&gt; 
&gt; I think that's the most obvious initial model to want when you do this sort
&gt; of thing, but I also think it's been beaten to death on the
&gt; context-switching issue. Consider if you have forty players on forty
&gt; threads; when ten of them go and talk, when each of them says something in
&gt; sequence you have ONE HUNDRED context switches. One for each of the players
&gt; who hear the speech, and one to return success to the initial thread,
&gt; making ten context switches for each statement times ten players. Yuck yuck
&gt; yuck.
&gt; 

I agree.  So don't do it that way.  :)  Why should a thread block just
because it's communicating with an object "controlled" by a different thread?

I think the say() method should look something like this:

void Character::say(string text) {
  foreach Chracter c in room
    lock c's input queue
    add { myName() + "says" + text } to c's input queue
    unlock c's input queue
  end
} 

Then when the thread or threads handling the other characters start running
that character, they pull the "say" event or text off the associated queue
and display it.  You only do a context switch when the lock is held _and_
another thread is runnable.  So you can either use non-blocking synchronization
(queue insertion can be done using atomic compare-and-swap) or use a number
of worker threads that's some multiple of the number of processors.
(If the amount of time the lock is held is likely to be &lt;= a context switch
time, then just sitting around is the right thing to do, though.)

The model Ross discusses keeps context switches to 0 in the absence
of contention.  (If there are other processes, you have to do "heavyweight"
context switching, of course.)

&gt; Or, the short form of the above: How do you balance the load before you
&gt; measure it?
&gt;

Good point.  You do load balancing dynamically---  if one thread falls behind 
in "simulated time", it's a sign that you need to reduce its 
responsibilities.  You _do_ gain by moving characters in the same area into 
the same worker thread, since that will probably reduce the number of lock 
conflicts.

Mark Gritter
mark#erdos,stanford.edu


_______________________________________________
MUD-Dev maillist  -  MUD-Dev#kanga,nu
<A  HREF="http://www.kanga.nu/lists/listinfo/mud-dev">http://www.kanga.nu/lists/listinfo/mud-dev</A>


</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<!--X-Follow-Ups-End-->
<!--X-References-->
<UL><LI><STRONG>References</STRONG>:
<UL>
<LI><STRONG><A NAME="00282" HREF="msg00282.html">Re: [MUD-Dev] Multi-threaded mud server.</A></STRONG>
<UL><LI><EM>From:</EM> Caliban Tiresias Darklock &lt;caliban#darklock,com&gt;</LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00296.html">RE: [MUD-Dev] Sockets</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00298.html">Re: [MUD-Dev] Multi-threaded mud server.</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00282.html">Re: [MUD-Dev] Multi-threaded mud server.</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00299.html">Re: [MUD-Dev] Multi-threaded mud server.</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00297"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00297"><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] Multi-threaded mud server.</STRONG>, <EM>(continued)</EM>
<ul compact>
<ul compact>
<ul compact>
<LI><strong><A NAME="00280" HREF="msg00280.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Travis S. Casey <a href="mailto:efindel#io,com">efindel#io,com</a>, Mon 17 May 1999, 15:24 GMT
<UL>
<LI><strong><A NAME="00298" HREF="msg00298.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Ola Fosheim Grøstad <a href="mailto:no#no,no">no#no,no</a>, Tue 18 May 1999, 06:44 GMT
</LI>
<LI><strong><A NAME="00339" HREF="msg00339.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Ross Nicoll <a href="mailto:rnicoll#lostics,demon.co.uk">rnicoll#lostics,demon.co.uk</a>, Fri 28 May 1999, 21:04 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00282" HREF="msg00282.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Caliban Tiresias Darklock <a href="mailto:caliban#darklock,com">caliban#darklock,com</a>, Mon 17 May 1999, 15:26 GMT
<UL>
<LI><strong><A NAME="00297" HREF="msg00297.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Mark Gritter <a href="mailto:mark#erdos,Stanford.EDU">mark#erdos,Stanford.EDU</a>, Tue 18 May 1999, 06:43 GMT
</LI>
<LI><strong><A NAME="00299" HREF="msg00299.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Ross Nicoll <a href="mailto:rnicoll#lostics,demon.co.uk">rnicoll#lostics,demon.co.uk</a>, Tue 18 May 1999, 06:45 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00284" HREF="msg00284.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Mon 17 May 1999, 15:46 GMT
<UL>
<LI><strong><A NAME="00294" HREF="msg00294.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Ross Nicoll <a href="mailto:rnicoll#lostics,demon.co.uk">rnicoll#lostics,demon.co.uk</a>, Tue 18 May 1999, 06:42 GMT
</LI>
</UL>
</LI>
</ul>
<LI><strong><A NAME="00283" HREF="msg00283.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Mon 17 May 1999, 15:45 GMT
</LI>
</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>

Site Stats

Snippets: 1791
Codebases: 571