1999Q2/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: Re: [MUD&#45;Dev] Multi&#45;threaded mud server. -->
<!--X-From-R13: [vx Qynexr <zvxpyexNvoz.arg> -->
<!--X-Date: Tue, 18 May 1999 00:01:50 &#45;0700 -->
<!--X-Message-Id: 37407C1C.6D47C501#ibm,net -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: Pine.LNX.4.10.9905162033590.4142&#45;100000@drpc&#45;jrn.res.st&#45;an d.ac.uk -->
<!--X-Reference: 199905170504.AAA19224@dfw&#45;ix5.ix.netcom.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:mikclrk#ibm,net">
</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="msg00300.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00302.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00283.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00302.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00301">Author</A>
&nbsp;|&nbsp;<A HREF="#00301">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00301">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>: Mik Clarke &lt;<A HREF="mailto:mikclrk#ibm,net">mikclrk#ibm,net</A>&gt;</LI>
<LI><em>Date</em>: Mon, 17 May 1999 21:29:16 +0000</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>
Jon A. Lambert wrote:

&gt; Yes, but I can't for the life of me figure out why it's so damn important
&gt; to avoid. ;)

Agreed, context switching is not expensive and it isn't a problem.  Most OSshave
it down pat by now.  Attempting to balance the load on the threads is
fairly pointless, as the system does not assign threads to particular CPUs.
Modern multi tasking systems will typically execute less than a thousand CPU
instructions between (involuntary) context switches. Threads get voluntarily
suspended as soon as they start waiting for something - I/O, page faults
etc...  The same thread will probably be batted around between the CPUs like
they were playing catch with it.

The reason you don't want more than 2 or 3 times as many threads than
CPUs:

When your application is busy - very busy, and all threads are demanding
attention, the CPU(s) will be fairly busy trying to service them all. If you have
many more threads than CPUs you end up with 'ready to dispatch' threads
waiting a long time to get some CPU.  Most threads will not be ready to dispatch.
They will either be idle or waiting for something else to happen (like I/O to
complete, or memory to be paged).  When you have enough ready threads to 95%
saturate the CPU, adding more threads won't make it go any faster.

For the mainframe product I work on we use a figure of 2-3 times the number
of CPUs for the threads.  This gives us good through put (our environment
has quite a lot of I/O in it) and leaves some CPU free for the rest of the
system.

Why some muds don't take to multi-threading:

If a Mud runs through an external database, it should multi-thread very well.  If
a mud runs from a single instorage, strucutre (ala LPs, Diku) it will not
multi-thread very well.  The main problem is that you either have to have
hundreads and thousands of semaphores to protect each data structure from
simultaneous access by multiple threads (ok when they are all reading, but
bad news when one or more of them is trying to make a (non-atomic) change).
The alternative is to lock the whole structure and make the threads wait for
thier turn before accessing it.  This lets them do I/O and validation type things
before they join the queue, and they need to know beforehand if they want to
read or update (multiple consecutive readers can be allowed).  For a Diku, such
a change is a big deal.

Mik




_______________________________________________
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="00283" HREF="msg00283.html">Re: [MUD-Dev] Multi-threaded mud server.</A></STRONG>
<UL><LI><EM>From:</EM> "Jon A. Lambert" &lt;jlsysinc#ix,netcom.com&gt;</LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00300.html">Re: [MUD-Dev] Custom Server Roll Call?</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00302.html">Re: [MUD-Dev] Multi-threaded mud server.</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00283.html">Re: [MUD-Dev] Multi-threaded mud server.</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00302.html">Re: [MUD-Dev] Multi-threaded mud server.</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00301"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00301"><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>
<ul compact>
<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><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
<UL>
<LI><strong><A NAME="00301" HREF="msg00301.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Mik Clarke <a href="mailto:mikclrk#ibm,net">mikclrk#ibm,net</a>, Tue 18 May 1999, 07:01 GMT
</LI>
<LI><strong><A NAME="00302" HREF="msg00302.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Jo Dillon <a href="mailto:emily#thelonious,new.ox.ac.uk">emily#thelonious,new.ox.ac.uk</a>, Tue 18 May 1999, 07:02 GMT
<UL>
<LI><strong><A NAME="00308" HREF="msg00308.html">Re: [MUD-Dev] Multi-threaded mud server.</A></strong>, 
Travis S. Casey <a href="mailto:efindel#io,com">efindel#io,com</a>, Wed 19 May 1999, 04:47 GMT
</LI>
<LI><strong><A NAME="00315" HREF="msg00315.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>, Thu 20 May 1999, 05:20 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00337" HREF="msg00337.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:03 GMT
</LI>
</UL>
</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>