Re: AIO vs. RISC OS; perl5 compatibility; subsystems (was: Re: Speaking of signals...)

2001-01-09 Thread Uri Guttman

 "RC" == Rocco Caputo [EMAIL PROTECTED] writes:


  RC Re: Writing the subsystems together.

  RC I think you misunderstand the other message's intent.  The main loop,
  RC the interpreter, and I/O, are three separate subsystems.  I think
  RC everyone agrees with you that they should be interchangeable, but
  RC their public interfaces are sufficiently intertwined that they should
  RC be designed, at least at their borders, as a complete system.

and that's what i have been saying but maybe not as clearly as i
could. the interactions between these subsystems is so critical to the
functionality and speed of perl6 that they must designed together. if we
can isolate them (so we can interchange modules) without a major
performance it, that would be a win. i would be willing to sacrifice
some flexibility for speed if there is a noticeable need for that.

uri

-- 
Uri Guttman  -  [EMAIL PROTECTED]  --  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  ---  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  --  http://www.northernlight.com



AIO and threads - my prejudices

2001-01-09 Thread Alan Burlison

Copied from p5p as it seemed kinda relevant.

Dan Sugalski wrote:

 Roll on perl6...
 
 Well, besides "Just don't *do* that," any thoughts on how to handle this
 properly in p6?

Hmm.  I've been half-following the async IO and signals thread in
perl6-internals.  The first thing I would say is that if you think there
are portability problems with threads and signals, wait until you get to
play with cross-platform AIO.  General received wisdom seems to be that
using multiple threads and synchronous IO is a much easier thing to get
working than trying to use the various difficult-to-use AIO APIs.

That leads nicely onto the next point - signals.  Again, the received
wisdom here is that if you are going to use threads and signals
together, you should have a dedicated signal handling thread which does
a sigwait and sets a flag when a signal occurs.  The flag would be
polled by the main loop and the signal handler called when it was safe
to do so.

Now I can see that at this point all you speed freaks want jump on me
and tell me how horribly inefficient this additional test would be.  I 
have only one thing to say to you - get real.  One conditional (even if
protected by a mutex) is neither here nor there when compared to the
number of instructions taken to implement a typical perl op, and you
wouldn't do it for every op dispatched anyway.  A sensible thing might
to be to get the compiler to emit statement boundary markers into its
output, and use these as points at which you check for and dispatch
signals.

For example, on my platform (sparc), an empty for loop takes about 10
cycles per iteration, a function call to setjmp takes about 10 cycles
and a call to sigsetjmp takes more than 5300 cycles, due largely to the
fact that it requires a syscall and is therefore also an invitation to
the OS to reschedule your process.  If you want to worry about
something, worry about that 5300 cycles first.  Then worry even more
that setjmp isn't thread safe either.

The upshot of all this is I think perl6 should be mandatorally threaded,
with a mixture of internal threads (signal handler, async IO handler,
garbage collector, whatever), and application threads.  Each application
thread would be an entire instance of the interpreter - none of that
crazy mutex madness that doomed the attempt to thread perl5. 
Interpreter threads would touch at well-defined points only - the aim
being to avoid mutexes as far as possible, rather than to infect
everything with them.  In the degenerate case (existing unthreaded
scripts) there would be only one interpreter instance and therefore only
one application thread.

This has lots of advantages - no changes in behaviour when threads are
used as perl is always threaded, well-defined semantics of how multiple
interpreters coexist and cooperate, system housekeeping can be
modularised and done behind the scenes in dedicated threads etc etc.

The downside is that we would restrict perl6 to only those platform that
supported threads.  I'm not sure how much of a restriction this would
turn out to be in practice - how many current perl platforms don't have
threads?

As for AIO - my guess is that faking it up with threads is a much better
bet.  After all, what proportion of apps are MT vs AIO, and which is
most likely to be available, well tested and well supported?

Alan Burlison