1998Q1/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: Event handling (was: request for comments) -->
<!--X-From-R13: f001tzhNabin.jevtug.rqh -->
<!--X-Date: Fri, 09 Jan 1998 21:51:45 +0000 -->
<!--X-Message-Id: Pine.PMDF.3.95.980109154422.543193470A&#45;100000#nova,wright.edu -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: 34B6630C.F926E320#4cs,com -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, Event handling (was: request for comments)</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="msg00152.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00154.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00143.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00155.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00153">Author</A>
&nbsp;|&nbsp;<A HREF="#00153">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00153">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>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>: Event handling (was: request for comments)</LI>
<LI><em>From</em>: <A HREF="mailto:s001gmu#nova,wright.edu">s001gmu#nova,wright.edu</A></LI>
<LI><em>Date</em>: Fri, 09 Jan 1998 16:52:16 -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 Fri, 9 Jan 1998, Vadim Tkachenko wrote:

&gt; s001gmu#nova,wright.edu wrote:
&gt; &gt; 
&gt; &gt; On Thu, 8 Jan 1998, Vadim Tkachenko wrote:
&gt; &gt; 

&lt;original question dropped&gt;

&gt; 
&gt; [skipped]
&gt; 
&gt; &gt; &gt; - One thread per connection listener (it's possible to install more than
&gt; &gt; &gt; one protocol adaptor, and therefore, connection listener)
&gt; &gt; &gt; - One thread per incoming connection
&gt; &gt; 
&gt; &gt; so... at least 2 threads per user?
&gt; 
&gt; Of course not - connection listener thread just accept()s the incoming
&gt; connections and
&gt; spawns the controlling thread

ahhh... gotcha.   I believe I am heading towards a model like this, though
if I understand what you mean by protocol adapter, I am only planning on
using one. 

&gt; &gt; The decision to go with ticks and a limited number of threads to handle
&gt; &gt; the events for a tick stems directly from concerns of system load.  I
&gt; &gt; don't want to design a game that _requires_ it be the only significant
&gt; &gt; process running on a server. 
&gt; 
&gt; Well, I look at it from slightly different point of view - 
&gt; 
&gt; - my MUD project is for fun, but this is a guinea pig for every new
&gt; idea/concept/technique
&gt; - If I would write that seriously, the commercial application is a
&gt; target, then why wouldn't I dedicate the computer to run it?

I am working from the perspective of possibly finding a benevolent
sysadmin, willing to share a server with me.  Different goals, different
tactics.  :)

&lt;humor snipped... ;) &gt; 

&lt;...&gt;
 
&gt; &gt; As I said, it's very much a result of a lot of factors, including, but not
&gt; &gt; limited to cpu speed, threads implementation, compiler, OS, the DB in
&gt; &gt; use... etc.
&gt; 
&gt; Aha, and I also forgot to think that I was not the only user on the site
&gt; at that time, so effectively fail-threshold lies above 50.

well, under those circumstances it did.  Other circumstances might drive
the number in various driections.
 
&gt; &gt; I am unfamiliar with the minSpare/maxSpare management strategy... the
&gt; &gt; O'reily PThreads book didn't discuss it, and as that's the only book I
&gt; &gt; really have avail... :)  Care to give a brief tutorial, or point me to a
&gt; &gt; web page?  I am a tinkerer at heart, and would prefer an algorithm/design
&gt; &gt; strategy to source code, as I prefer to code my own stuff.  :)
&gt; 
&gt; And I've never heard about PThreads book... See, all my knowledge is 99%
&gt; experience-based - you know, when O'Reilly book eats out 50% of your
&gt; monthly income (which was true until recently for me), guess what...

It's a pretty good book, though it only deals with somewhat cursory
examples, and is (obviously) about only the Posix Threads Standard.  It
does have some very nice, if somewhat general, discussions of optimization
and how to evaluate performance of a threaded program.
 
&gt; OK, so the minSpare/maxSpare strategy is what I saw in Apache HTTPD
&gt; (<A  HREF="http://www.apache.org">http://www.apache.org</A>).

thanky much... I'll take a peek at that right-quick.
 
&gt; - You keep at least minSpare spare request handlers, just in case, so
&gt; first minSpare incoming
&gt; requests arriving simultaneously will be served really fast.
&gt; - After some requests are finished, you keep at most maxSpare spare
&gt; request handlers, terminating anything extra (variation: after they
&gt; expire by themselves).

I figgured it was something like that.  True, that does seem to localize
most of the thread-creation cost to boot-time.  Especially if you pick a
decent range and initial number of threads.
 
&gt; That's basically it. Also, the implied consideration is you have to have
&gt; maxRunning request handlers and never exceed the limit or you're likely
&gt; to hit the system limits - just couple of examples:

of course... :)
 
&gt; - Artificial limit on evaluation versions of JDBC implementations
&gt; - MAX_THREAD
&gt; 
&gt; Also, you may consider dynamically change minSpare, maxSpare and
&gt; maxRunning depending on other conditions.
&gt; 
&gt; Also, there are two types of requests worth mentioning:
&gt; 
&gt; - packet request
&gt; - channel request

have to read up a bit, but I think I gather the gist of the points.. :)
 
&gt; &gt; mmm.. even in an asynchronous event handler, you can get two events
&gt; &gt; targetting the same data executing at 'the same time'.  This requires
&gt; &gt; either a lockless/rollback method or a data locking method.
&gt; 
&gt; Well, there are known methods to resolve this - either mutex semaphores
&gt; or synchronized methods in Java (btw, the absense of semaphores in Java
&gt; was really annoying, so I recreated them :-)

uh... exactly.  which was the point of my mentioning the discussion on
lockless v. locked model.  both are well tested and accepted models for
handling data integrity in MT environs, synchronous or otherwise...
 
&gt; &gt; Well, when you come down to it, even a so-called asynchronous model is
&gt; &gt; still time-slice or tick-based.  the system's clock just has a very fine
&gt; &gt; grain.  I suppose it's a throw-back to paper RPGs.  I played a lot of them
&gt; &gt; for many years (really haven't played much the past couple... *sigh*), and
&gt; &gt; it's hard to break out of the mold they establish.
&gt; 
&gt; Yeah, it was different for me - with my computer experience with games
&gt; which didn't engage turns (at least, obviously), like Eye of Beholder,
&gt; Ultima Underworld, I had no prejudice

*nod*  our end goal is to not make it obvious to the player that the game
is turn based, but the underlying mechanics will be.  The more that I
think about it, the less I like the 'tick' idea... Why artificially impose
a less granular clock on top of the system clock?  Why not just let the
system clock determine the timing?  Situations where the character's speed
should be far faster than the players typing speed (IE: combat, etc), can
(and should?) be handled by the computer (IE: the computer is generating
the events, not player commands).  All other commands don't need to be
turn-based, as speed has already been deemd uniportant by the designer
(me), by that system not being coded as an auto-generated event.

mmm... ahh well.  another redesign spawned by the list.. *grumble*  ;)
 
&gt; &gt; but when I tell my
&gt; &gt; character to "cast fireball at bubba", it becomes trivial to implement the
&gt; &gt; delay inherent to the action by scheduling the event to go off 3 ticks
&gt; &gt; down the road.
&gt; 
&gt; By the way, this is exactly the point where extra threads appear in my
&gt; model. Every time-based action is asynchronously handled by the separate
&gt; thread, which allows to handle effects like spell backfires,
&gt; concentration, partial force release, accumulation rules, side effects
&gt; with extreme ease.

*nod*  I think I see where you are going.. the event, "cast spell" is
plunked on the queue, and handled as quickly as possible.  Handling means
calling a method which may "sleep" for a while, to take care of the delay.
If it's interrupted while sleeping (someone interrupts bubba casting the
spell), you have some sort of 'interuppted' method which handles the
results of someone busting up bubba's concentration.  Right?

That being the case, I'd still prefer to let events spend their delay time
on the queue, instead of in a thread.  Each sleeping thread is a thread
that could be used by something else.  Why allocate a scarse resource
before it's 100% needed?  Again, this harks back to my initial goals, of
building a non-cpu intensive game... well, at least, less so than other
games... ;)
 
&gt; &gt; yes, you could just as easily let bubba's character wait for however long
&gt; &gt; and then generate a 'fireball is cast at bubba from boffo' event, to be
&gt; &gt; handled immediately.  Either way works.  It's just a matter of where you
&gt; &gt; choose to do your time and potential interrupt handeling.
&gt; 
&gt; See, I do not consider 'cast fireball' as EVENT. I consider it as a
&gt; PROCESS.

*nod*  see above... 
 
&gt; &gt; &gt; Let me point out one possible common target: if you use the concept of
&gt; &gt; &gt; context, or environment, and it's not a fixed value, then ...
&gt; &gt; &gt;
&gt; &gt; &gt; Like, time, weather in the area, gravity, etc.
&gt; &gt; 
&gt; &gt; mmm.. definately something to consider.  Thanks.  Anything else I missed,
&gt; &gt; anyone?  ;)
&gt; 
&gt; Just an idea: lycanthrops, whose properties change with a phase of the
&gt; moon[s]

mmm.. I dunno that that is really a valid concern... I am leaning more and
more towards JC's Spoof/Watcher model, which allows for such things
nicely (definately planning on spoofs.. still thinking about watchers..
dunno if my design goals necessarily coincide with the ones you chose that
lead to spoofs/watchers, JC).  W/O using watchers (to watch the phase of
the moon), I would schedule an event to go off at the beginning of the
time the lycanthrop should morph, to trigger the morph, and then one to go
off at the end of the time, to morph the poor bastich back.  No real
worries about multiple events targeting the same data at the same time, as
the events would occure once a month!  :)

an example of what I am concerned about would be something like:
bubba and biffy both blast boffo with a ball of blazing fire, in
rapid succession.  Both fireballs go off at close enough to the same time
that the handle_event methods are both trying to access boffo's soon to be
much depleted HP stat at the same time.  Reducing the number of such ...
collisions (?) is a primary goal... less collisions, the less time you
spend with threads waiting on eachother to release locks (IE: executing
serialy, not in parallel)

&lt;handling events in list at termination/reboot&gt;

  &lt;two options, handle at termination or save and handle at startup&gt;

 &lt;my response of "mm.. maybe best to just let them die at termination&gt;

&gt; 
&gt; Bad thing for me, because I'll have a lot of asynchronous events for
&gt; each object - for example, I'm going to implement the algorithm of
&gt; applying the temporary changes, illustrated by example:
&gt; 
&gt; - You get hit by the poisoned sword.
&gt; - Consequently, there are two state changes: your limb gets a wound
&gt; (let's make it a light one), and you get poisoned.
&gt; - Wound is going to heal by itself, slowly (asynchronous process, which,
&gt; in according to the abovementioned flexibility, may have variable rate
&gt; depending on your state, weather, nutrition etc.)
&gt; - Poison is going to continue to affect you (asynchronous process), once
&gt; again, with variable rate as above.

mmm.. so you handle all state changes, and resulting moves back towards
the norm as an event-process?  (IE: each wound is treated as an event?)
I think I'd treat the situation as a whole, rather than each individual
wound.  IE: there is one event logged (for each &lt;thing&gt; that is not at
it's normal state) which takes care of moving that thing back towards it's
normal state.  If I get a wound, it schedules the normalizer to go off
whenever, to up my hp a bit and reschedule another normalizer event.  If I
get another wound, the wound event wouldn't schedule a new normalizer,
'cause one is already pending for the previous wound.  how the normalizer
is scheduled can be as complicated as you like.

I'm thinking the best solution might be to fall back on DB backups...
every &lt;so often&gt; the program dumps a 'current state' of the pc to the DB.
if a crash occurs, the last 'current state' is loaded.  Current states
would include enough info to reconstruct the events for the character in
question.  Some events would have to be handled seperately... combat type
events, etc.  mmm.. definately requires some thought.  Mayhaps I shall go
dig up my concurant software design notes, and DB notes on rollback
techniques.

The main issue I see is:

Bubba and Boffo are fighting.  Bubba and Boffo are on different clocks for
their 'db backup' events.  Combat is interrupted by a crash / termination
/ reboot / whatever.  If all events are stored in the db backup, Bubba and
Boffo will have different pending combat events, based on the different
times at which their last backup was made.

Easy solution, put everyone on the same clock.
problem: large db writes, all at once.  slams system pretty good with a
lot of ppl on.

definately a DB rollback issue.
 
Any comments from the peanut gallery?  :)

-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="00195" HREF="msg00195.html">Re: [MUD-Dev] Event handling (was: request for comments)</A></strong>
<ul compact><li><em>From:</em> JC Lawrence &lt;claw#under,Eng.Sun.COM&gt;</li></ul>
<li><strong><A NAME="00155" HREF="msg00155.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="00143" HREF="msg00143.html">Re: [MUD-Dev]  Event handling (was: request for comments)</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="msg00152.html">Re: [MUD-Dev] Text vs Video; Movies, Books &amp; muds.</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00154.html">Re: [MUD-Dev] Unique items (was: Graphic MUDS/Ultima Online)</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00143.html">Re: [MUD-Dev]  Event handling (was: request for comments)</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00155.html">Re: [MUD-Dev]  Event handling (was: request for comments)</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00153"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00153"><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>Event handling (was: request for comments)</STRONG>, <EM>(continued)</EM>
<ul compact>
<ul compact>
<ul compact>
<ul compact>
<ul compact>
<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><strong><A NAME="00222" HREF="msg00222.html">[MUD-Dev]  Event handling - some definitions</A></strong>, 
Jon A. Lambert <a href="mailto:jlsysinc#ix,netcom.com">jlsysinc#ix,netcom.com</a>, Tue 13 Jan 1998, 00:55 GMT
</LI>
</LI>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</UL>
</LI>
</ul>
</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>