1998Q3/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: [MUD&#45;Dev] Re: async i/o and threads (was: Re: lurker emerges) -->
<!--X-From-R13: "Xnzrf Ivyfba" <wjvyfbaNebpurfgre.ee.pbz> -->
<!--X-Date: Mon, 10 Aug 1998 19:44:37 &#45;0700 -->
<!--X-Message-Id: 001001bdc4d0$f9661360$961e5d18#default,rochester.rr.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] Re: async i/o and threads (was: Re: lurker emerges)</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:jwilson#rochester,rr.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="msg00645.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00647.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00655.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00650.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00646">Author</A>
&nbsp;|&nbsp;<A HREF="#00646">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00646">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>[MUD-Dev] Re: async i/o and threads (was: Re: lurker emerges)</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: &lt;<A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A>&gt;</LI>
<LI><em>Subject</em>: [MUD-Dev] Re: async i/o and threads (was: Re: lurker emerges)</LI>
<LI><em>From</em>: "James Wilson" &lt;<A HREF="mailto:jwilson#rochester,rr.com">jwilson#rochester,rr.com</A>&gt;</LI>
<LI><em>Date</em>: Mon, 10 Aug 1998 22:37:21 -0400</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#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>

-----Original Message-----
From: J C Lawrence &lt;claw#under,engr.sgi.com&gt;
To: mud-dev#kanga,nu &lt;mud-dev#kanga,nu&gt;
Date: Monday, August 10, 1998 3:04 PM
Subject: [MUD-Dev] Re: lurker emerges


&gt;On Sun, 9 Aug 1998 02:06:56 -0400
&gt;James Wilson&lt;jwilson#rochester,rr.com&gt; wrote:
&gt;
&gt;&gt; my first issue is basic server control flow: select() vs. threading
&gt;&gt; vs...?  There are some startling numbers at the thttpd web site
&gt;&gt; (&lt;url: <A  HREF="http://www.acme.com/software/thttpd">http://www.acme.com/software/thttpd</A>&gt;) showing the vast
&gt;&gt; difference between single-threaded, select()-based http servers and
&gt;&gt; servers based on other models (using one-thread-per-connection or a
&gt;&gt; thread pool). This was a bit of a shock to me as I am quite enamored
&gt;&gt; of threading (probably more because of its challenges than because
&gt;&gt; of its necessity, I am forced to admit). I am curious as to what
&gt;&gt; approaches the list readers feel are tenable, and what their pros
&gt;&gt; and cons are.
&gt;
&gt;You need to read the following:
&gt;
&gt;  <A  HREF="http://www.kanga.nu/~petidomo/lists/mud-dev/1998Q2/msg01208.html">http://www.kanga.nu/~petidomo/lists/mud-dev/1998Q2/msg01208.html</A>
&gt;
&gt;The concerns and the mechanics are not unique to Linux.

Thanks for the reference. I read it a couple of days ago when I was poking
through the archive, but it's more useful to me now after the recent
discussions.
Portability question: does the select() available with the mingw32 system
(which
might come straight out of winsock, I don't know) have any gotchas? I can
get about 20-30 connections accepted per second, with the client on the
local
machine; that seems plenty fast to me.

With respect to the idea of two sets of sockets, one 'active' and one
'inactive',
should one divide the active sockets into active-read and active-write
sockets?
That is, perhaps a socket's getting sent a lot of data on a regular basis
but doesn't send much back; it would be a bit of a waste to check it for
read-availability
as often as write-availability.

I've been trying to suss out how the async i/o model would work, especially
if
any given request might be cpu-intensive... please bear with me if this is a
'duh'.
I am imagining:

1. the i/o thread(s) use(s) select() to find the readable and writeable
sockets.
for a readable socket, it does a non-blocking read() and whatever amount of
data comes in goes into a bucket. if the data in the bucket is a complete
request,
something is done with it (see 2, below). for a writeable socket, there's a
buffer
containing stuff you want to send out; if it's nonempty, you do a
non-blocking write()
and adjust the buffer according to how much actually got write()ed.

2. (a) if you're single-threading, then every time you get a complete
request you go
off somewhere and process it. possibly you could do something with timeouts
so
this processing time is bounded, but this seems pretty hairy. otherwise I
guess you
have to ensure that not much time will be spent in the 'real work'. When you
do output
to sockets, you just dump the data in the socket's buffer; I'm not down with
the
technicalities of buffering, so I'm not sure if the buffer should grow
dynamically, drop
the data, or fail in some way that allows the data to be resent when the
buffer's
got some room.
   (b) if you're multi-threading, things are much the same; threads respond
to complete
requests and write their output into per-socket buffers. the catch here is
synchronizing
with the main thread; you could mutex each socket buffer, but then a popular
socket (where lots of worker threads are writing into it) could make the i/o
thread
sit there waiting for the lock for a long time. Maybe there's a way around
this?

The reason I'm paranoid about the amount of time spent in processing is user
scripts; I'm sure I can't trust people not to write inefficient or
infinite-looping code,
and it'd sure be nice to have the latter locked away in a thread so they
don't
prevent others from logging in (or me from killing the runaway). I'm not
sure how
this could be accomplished cleanly in a single thread. Also, if one uses a
disk-based
system, 'zone faults' would seem to be a great thing to put in a thread
separate
from the socket i/o thread.

I'm a bit concerned about the overhead of using a thread pool, though, since
my two
target platforms (win32 and linux) use heavyweight threads. Has anyone tried
a bytecode vm that implements user-level threads, setting up a scheduler
that timeslices between 'processes', switches context on blocking i/o, and
so on? Maybe this could give you lightweight, portable threading while
keeping the whole process in a single thread? I'm imagining something where
the main thread is either chomping bytecode or checking for io-ready
sockets.

James




</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="00650" HREF="msg00650.html">[MUD-Dev] Re: async i/o and threads (was: Re: lurker emerges</A></strong>
<ul compact><li><em>From:</em> "Jon A. Lambert" &lt;jlsysinc#ix,netcom.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="msg00645.html">[MUD-Dev] Re: META: List combat character and racial memory (was Re: Affordances and social method (Was: Re: Wire d Magazine...))</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00647.html">[MUD-Dev] Re: Adverts in email on the list.</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00655.html">[MUD-Dev] Re: async i/o and threads (was: Re: lurker emerges</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00650.html">[MUD-Dev] Re: async i/o and threads (was: Re: lurker emerges</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00646"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00646"><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>[MUD-Dev] Re: clients anyone?...</STRONG>, <EM>(continued)</EM>
<ul compact>
<LI><strong><A NAME="01064" HREF="msg01064.html">[MUD-Dev] Re: clients anyone?...</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Fri 18 Sep 1998, 20:51 GMT
<UL>
<LI><strong><A NAME="01081" HREF="msg01081.html">[MUD-Dev] Re: clients anyone?...</A></strong>, 
Andrew Wilson <a href="mailto:andrew#aaaaaaaa,demon.co.uk">andrew#aaaaaaaa,demon.co.uk</a>, Sun 20 Sep 1998, 00:58 GMT
</LI>
</UL>
</LI>
</ul>
</LI>
<LI><strong><A NAME="00651" HREF="msg00651.html">[MUD-Dev] Re: async i/o and threads (was: Re: lurker emerges</A></strong>, 
James Wilson <a href="mailto:jwilson#rochester,rr.com">jwilson#rochester,rr.com</a>, Tue 11 Aug 1998, 04:20 GMT
<UL>
<LI><strong><A NAME="00655" HREF="msg00655.html">[MUD-Dev] Re: async i/o and threads (was: Re: lurker emerges</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Tue 11 Aug 1998, 06:58 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00646" HREF="msg00646.html">[MUD-Dev] Re: async i/o and threads (was: Re: lurker emerges)</A></strong>, 
James Wilson <a href="mailto:jwilson#rochester,rr.com">jwilson#rochester,rr.com</a>, Tue 11 Aug 1998, 02:44 GMT
<UL>
<LI><strong><A NAME="00650" HREF="msg00650.html">[MUD-Dev] Re: async i/o and threads (was: Re: lurker emerges</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Tue 11 Aug 1998, 03:56 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00639" HREF="msg00639.html">[MUD-Dev] Re: META: List combat character and racial memory (was Re: Affordances and social method (Was: Re: Wire d Magazine...))</A></strong>, 
kamikaze <a href="mailto:kamikaze#kuoi,asui.uidaho.edu">kamikaze#kuoi,asui.uidaho.edu</a>, Mon 10 Aug 1998, 20:50 GMT
<UL>
<LI><strong><A NAME="01057" HREF="msg01057.html">[MUD-Dev] Re: META: List combat character and racial memory (was Re: Affordances and social method (Was: Re: Wire d Magazine...))</A></strong>, 
J C Lawrence <a href="mailto:claw#under,engr.sgi.com">claw#under,engr.sgi.com</a>, Thu 17 Sep 1998, 01:07 GMT
</LI>
</UL>
<UL>
<li>&lt;Possible follow-up(s)&gt;<br>
<LI><strong><A NAME="00645" HREF="msg00645.html">[MUD-Dev] Re: META: List combat character and racial memory (was Re: Affordances and social method (Was: Re: Wire d Magazine...))</A></strong>, 
Chris Gray <a href="mailto:cg#ami-cg,GraySage.Edmonton.AB.CA">cg#ami-cg,GraySage.Edmonton.AB.CA</a>, Tue 11 Aug 1998, 02:40 GMT
</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>