Pardon my misreading...

Marc Lehmann schmorp at schmorp.de
Fri Jan 4 15:58:30 CET 2013


On Wed, Jan 02, 2013 at 10:23:13AM -0500, Michael Alan Dorman <mdorman at ironicdesign.com> wrote:
> My desire was to try and specialize the code that handles fulfilling the
> promises to give the event loop an opportunity to run between steps, in
> order to increase throughput for the overall system at the cost of some
> latency for long chains of promises.  This would mean that even
> relatively heavyweight processing of results---assuming they were
> amenable to pipeline-style-processing---could have lower impact on
> system throughput.

Ok, it is now more clear on what you are trying to do.

I think what you are looking for is idle watchers indeed.

Note that you cannot implement this behaviour portably (not all event
loops have this kind of concept).

If you want to rate-limit processing, an explicit timer is probably doing
that, resulting in some tunable value (the interval, potentially adjusted
by load, which you can measure by the number of outstanding callbacks).

However, overall, the problem you want to solve, while a valid problem,
can't really be solved with AnyEvent (or most event loops, or even in
general).

The closest you can come to that is using e.g. an idle watcher (and
possibly a timer to guarantee progress, which might or might not be
necessary).

> However, the moment I had two steps, they would both run to completion
> before the event loop ran again because the recursive invocation of
> postpone (remember, the cascade of promises is effectively handled
> recursively)---so that was no better than the original behavior.

Well, it's not handled recursively, so in this respect, it's better than
the original behaviour if you think that recursive handling is bad.

Lastly, looking again at your code, do you really need to write it in such
a complicated manner? Wouldn't a normal if statement work just fine?

The only time where you can't really do this is when you wait for an
external event, in which case the desired behaviour happens automatically
(depending on the whim of the event loop in use, which is usually good
enough).

So the problem seems to only occur when you use promises excessively where
they serve no purpose (no events are involved) - why split essentially
linear code into callbacks?

-- 
                The choice of a       Deliantra, the free code+content MORPG
      -----==-     _GNU_              http://www.deliantra.net
      ----==-- _       generation
      ---==---(_)__  __ ____  __      Marc Lehmann
      --==---/ / _ \/ // /\ \/ /      schmorp at schmorp.de
      -=====/_/_//_/\_,_/ /_/\_\



More information about the anyevent mailing list