1998Q1/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: Re: [MUD&#45;Dev]  Event handling (was: request for comments) -->
<!--X-From-R13: Hnqvz Fxnpuraxb <inqvzgN4pf.pbz> -->
<!--X-Date: Fri, 09 Jan 1998 17:50:53 +0000 -->
<!--X-Message-Id: 34B6630C.F926E320#4cs,com -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: Pine.PMDF.3.95.980109094922.543180133A&#45;100000#nova,wright.edu -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, Re: [MUD-Dev]  Event handling (was: request for comments)</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:vadimt#4cs,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="msg00144.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00145.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00147.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00153.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00143">Author</A>
&nbsp;|&nbsp;<A HREF="#00143">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00143">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>Re: [MUD-Dev]  Event handling (was: request for comments)</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>: Re: [MUD-Dev]  Event handling (was: request for comments)</LI>
<LI><em>From</em>: Vadim Tkachenko &lt;<A HREF="mailto:vadimt#4cs,com">vadimt#4cs,com</A>&gt;</LI>
<LI><em>Date</em>: Fri, 09 Jan 1998 11:49:00 -0600</LI>
<LI><em>Sender</em>: <A HREF="mailto:vt#vadimt,4cs.com">vt#vadimt,4cs.com</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
s001gmu#nova,wright.edu wrote:
&gt; 
&gt; On Thu, 8 Jan 1998, Vadim Tkachenko wrote:
&gt; 
&gt; &gt; s001gmu#nova,wright.edu wrote:
&gt; &gt; &gt;
&gt; &gt; &gt; On Mon, 5 Jan 1998, Vadim Tkachenko wrote:
&gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt;Jon A. Lambert wrote:
&gt; &gt; &gt;
&gt; &gt; &gt; ...
&gt; &gt; &gt;
&gt; &gt; &gt; &gt;&gt;  Variations on event-driven design
&gt; &gt; &gt; &gt;
&gt; &gt; &gt; &gt;Can you please elaborate on that?
&gt; &gt; &gt;

[skipped]

&gt; &gt; - One thread per connection listener (it's possible to install more than
&gt; &gt; one protocol adaptor, and therefore, connection listener)
&gt; &gt; - One thread per incoming connection
&gt; 
&gt; so... at least 2 threads per user?

Of course not - connection listener thread just accept()s the incoming
connections and
spawns the controlling thread

&gt; The decision to go with ticks and a limited number of threads to handle
&gt; the events for a tick stems directly from concerns of system load.  I
&gt; don't want to design a game that _requires_ it be the only significant
&gt; process running on a server. 

Well, I look at it from slightly different point of view - 

- my MUD project is for fun, but this is a guinea pig for every new
idea/concept/technique
- If I would write that seriously, the commercial application is a
target, then why wouldn't I dedicate the computer to run it?

A while ago (in 1992), I heard a joke which bottomline was - "any
mention about the performance UNIX geeks consider obscene". Well, I
laughed, but then, when I came to UNIX, I understood the pun - "if it's
slow, put it in background and forget about it until it's done".

&gt; &gt; Well, a while ago I've been told to implement a Web crawler for a site,
&gt; &gt; and the first thought was - just to go to the root URL, read and parse
&gt; &gt; it and as links appear, spawn other threads using the same algorithm.
&gt; &gt;
&gt; &gt; Obviously, you can parse the HTTP stream much faster than server
&gt; &gt; produces it, and, well, www.best.com (a guinea pig for that task)
&gt; &gt; started to fail when, say, something like 50th request thread was
&gt; &gt; started. Funny, but on my side (Linux, JDK 1.02) nothing bad happened.
&gt; 
&gt; As I said, it's very much a result of a lot of factors, including, but not
&gt; limited to cpu speed, threads implementation, compiler, OS, the DB in
&gt; use... etc.

Aha, and I also forgot to think that I was not the only user on the site
at that time, so effectively fail-threshold lies above 50.

&gt; I am unfamiliar with the minSpare/maxSpare management strategy... the
&gt; O'reily PThreads book didn't discuss it, and as that's the only book I
&gt; really have avail... :)  Care to give a brief tutorial, or point me to a
&gt; web page?  I am a tinkerer at heart, and would prefer an algorithm/design
&gt; strategy to source code, as I prefer to code my own stuff.  :)

And I've never heard about PThreads book... See, all my knowledge is 99%
experience-based - you know, when O'Reilly book eats out 50% of your
monthly income (which was true until recently for me), guess what...

OK, so the minSpare/maxSpare strategy is what I saw in Apache HTTPD
(<A  HREF="http://www.apache.org">http://www.apache.org</A>).

- You keep at least minSpare spare request handlers, just in case, so
first minSpare incoming
requests arriving simultaneously will be served really fast.
- After some requests are finished, you keep at most maxSpare spare
request handlers, terminating anything extra (variation: after they
expire by themselves).

That's basically it. Also, the implied consideration is you have to have
maxRunning request handlers and never exceed the limit or you're likely
to hit the system limits - just couple of examples:

- Artificial limit on evaluation versions of JDBC implementations
- MAX_THREAD

Also, you may consider dynamically change minSpare, maxSpare and
maxRunning depending on other conditions.

Also, there are two types of requests worth mentioning:

- packet request
- channel request

&gt; mmm.. even in an asynchronous event handler, you can get two events
&gt; targetting the same data executing at 'the same time'.  This requires
&gt; either a lockless/rollback method or a data locking method.

Well, there are known methods to resolve this - either mutex semaphores
or synchronized methods in Java (btw, the absense of semaphores in Java
was really annoying, so I recreated them :-)

&gt; Well, when you come down to it, even a so-called asynchronous model is
&gt; still time-slice or tick-based.  the system's clock just has a very fine
&gt; grain.  I suppose it's a throw-back to paper RPGs.  I played a lot of them
&gt; for many years (really haven't played much the past couple... *sigh*), and
&gt; it's hard to break out of the mold they establish.

Yeah, it was different for me - with my computer experience with games
which didn't engage turns (at least, obviously), like Eye of Beholder,
Ultima Underworld, I had no prejudice

&gt; but when I tell my
&gt; character to "cast fireball at bubba", it becomes trivial to implement the
&gt; delay inherent to the action by scheduling the event to go off 3 ticks
&gt; down the road.

By the way, this is exactly the point where extra threads appear in my
model. Every time-based action is asynchronously handled by the separate
thread, which allows to handle effects like spell backfires,
concentration, partial force release, accumulation rules, side effects
with extreme ease.

&gt; yes, you could just as easily let bubba's character wait for however long
&gt; and then generate a 'fireball is cast at bubba from boffo' event, to be
&gt; handled immediately.  Either way works.  It's just a matter of where you
&gt; choose to do your time and potential interrupt handeling.

See, I do not consider 'cast fireball' as EVENT. I consider it as a
PROCESS.

&gt; &gt; Let me point out one possible common target: if you use the concept of
&gt; &gt; context, or environment, and it's not a fixed value, then ...
&gt; &gt;
&gt; &gt; Like, time, weather in the area, gravity, etc.
&gt; 
&gt; mmm.. definately something to consider.  Thanks.  Anything else I missed,
&gt; anyone?  ;)

Just an idea: lycanthrops, whose properties change with a phase of the
moon[s]

&gt; &gt; Two options:
&gt; &gt;
&gt; &gt; - save the event list and process it on the startup
&gt; &gt; - process all the list on shutdown. But, this situation may be more
&gt; &gt; difficult because events being processed may produce some more effects
&gt; &gt; and so on - for example, if you shout (RL) and then try to 'process the
&gt; &gt; event while shutting down', you're likely to:
&gt; &gt;
&gt; &gt; - Hear the echoes,
&gt; &gt; - Which may, in turn, cause the avalanche,
&gt; &gt; - Which may, in turn, kill a lot of people around,
&gt; &gt; - Which, in turn, creates a LOT of other events to process,
&gt; &gt; - and so on.
&gt; 
&gt; *nod*  good point.  I just realized that one of the other things we
&gt; planned to do would work nicely with saving events and processing them at
&gt; re-start...  We planned on setting it up so that if you logout outside of
&gt; an inn or other "long-term storage" type safe-room, your character just
&gt; sits there...  so, in the event of a... less than expected shutdown, all
&gt; events are saved, all characters out and about are saved as such.  reboot,
&gt; all characters are put back, and all events are reloaded.  Rather nicely
&gt; takes care of problems like "cast fireball boffo" being reloaded with
&gt; neither the caster or the target being around. I can see players being
&gt; unhappy with the way things would work out, though.  It might be better
&gt; to just let the events die.

Bad thing for me, because I'll have a lot of asynchronous events for
each object - for example, I'm going to implement the algorithm of
applying the temporary changes, illustrated by example:

- You get hit by the poisoned sword.
- Consequently, there are two state changes: your limb gets a wound
(let's make it a light one), and you get poisoned.
- Wound is going to heal by itself, slowly (asynchronous process, which,
in according to the abovementioned flexibility, may have variable rate
depending on your state, weather, nutrition etc.)
- Poison is going to continue to affect you (asynchronous process), once
again, with variable rate as above.

In other words, I'm not going to save only the event queue, but also the
[logical] process context, too.

&gt; -Greg

PS: Once again, everything mentioned here is elaborated on
<A  HREF="http://vadimt.4cs.com/~vt/gradient">http://vadimt.4cs.com/~vt/gradient</A>, the particular example with a wound
is described under 'Wounds' section, generalized as property modifier.
-- 
Still alive and smile stays on,
Vadim Tkachenko &lt;VadimT#4CS,Com&gt;
--
UNIX _is_ user friendly, he's just very picky about who his friends are

</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="00153" HREF="msg00153.html">Event handling (was: request for comments)</A></strong>
<ul compact><li><em>From:</em> s001gmu#nova,wright.edu</li></ul>
</UL></LI></UL>
<!--X-Follow-Ups-End-->
<!--X-References-->
<UL><LI><STRONG>References</STRONG>:
<UL>
<LI><STRONG><A NAME="00141" HREF="msg00141.html">Event handling (was: request for comments)</A></STRONG>
<UL><LI><EM>From:</EM> s001gmu#nova,wright.edu</LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00144.html">Re: [MUD-Dev]  Event handling</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00145.html">Re: [MUD-Dev]  Commercial value of RP</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00147.html">Re: [MUD-Dev]  Event handling</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00153.html">Event handling (was: request for comments)</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00143"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00143"><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]  Event handling (was: request for comments)</STRONG>, <EM>(continued)</EM>
<ul compact>
<ul compact>
<ul compact>
<ul compact>
<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>
<LI><strong><A NAME="00143" HREF="msg00143.html">Re: [MUD-Dev]  Event handling (was: request for comments)</A></strong>, 
Vadim Tkachenko <a href="mailto:vadimt#4cs,com">vadimt#4cs,com</a>, Fri 09 Jan 1998, 17:50 GMT
<UL>
<LI><strong><A NAME="00153" HREF="msg00153.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, 21:51 GMT
<UL>
<LI><strong><A NAME="00155" HREF="msg00155.html">Re: [MUD-Dev]  Event handling (was: request for comments)</A></strong>, 
Vadim Tkachenko <a href="mailto:vadimt#4cs,com">vadimt#4cs,com</a>, Fri 09 Jan 1998, 23:03 GMT
<UL>
<LI><strong><A NAME="00198" HREF="msg00198.html">Re: [MUD-Dev] Event handling (was: request for comments)</A></strong>, 
JC Lawrence <a href="mailto:claw#under,Eng.Sun.COM">claw#under,Eng.Sun.COM</a>, Sun 11 Jan 1998, 21:09 GMT
<LI><strong><A NAME="00209" HREF="msg00209.html">Event handling (was: request for comments)</A></strong>, 
s001gmu <a href="mailto:s001gmu#nova,wright.edu">s001gmu#nova,wright.edu</a>, Mon 12 Jan 1998, 14:41 GMT
</LI>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</ul>
</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>