[Twisted-Python] How to Solve a Problem Like Santa with Stackless and Twisted

Johann Borck johann.borck at densedata.com
Wed Dec 14 08:31:11 MST 2011


On 12/14/2011 05:45 AM, Glyph wrote:
> On Dec 13, 2011, at 2:04 PM, Andrew Francis wrote:
>
>> Now at time T, there are eight reindeer and two elves ready. At T+1, an additional  reindeer and 
>> elf are ready (their timestamps are the same, timer resolution notwithstanding). However the 
>> Twisted reactor will serialise the events and trigger the callback. For argument, let us pretend 
>> the elvesArrive callback is activated and that wakes Santa. Santa consults with the elves. The 
>> problem is that all nine reindeer were ready and the priority rule is broken. I am not sure, from 
>> inside the callback, one could check to see if nine reindeer were indeed ready.
>
> This strikes me as a problem with the way that quantum physics works more than the way that 
> Twisted's reactor works :).  Broadly speaking, no two events can happen at the /exact/ same time; 
> even if they did, relativity says you wouldn't be able to /tell/ if they happened at the exact 
> same time unless they also happened to be exactly the same distance away from you.  (But then 
> "you" would have to be exactly one atom big, which is a pretty demanding size to build a sensor.)
> [...]
> Ultimately however, the order of the work /will/ be arbitrary; if it's not influenced by the 
> vagaries of Twisted's scheduler, it will be influenced by something in the kernel scheduler that 
> you don't understand or can't control, or in the IP stack, or in a switch on your network, or in 
> your hosting provider's firewall configuration, or something on a client machine that you truly 
> have no influence over at all.  Having something give priority to an event that occurs at "the 
> same" time given all of these potential sources of interference is basically pointless.
>
Isn't that  what logical clocks, using e.g. Lamport timestamps are for? What can be done is letting 
the events happen, wait for another logical tick, possibly triggered by a timeout to prevent 
starvation, looking at the events that have been collected and identified, but not processed yet, 
treating a certain maximum N of logical ticks as "simultaneous" and then decide on how to prioritize 
processing, based on arbitrary rules you choose.

regards,
Johann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20111214/167d6bed/attachment.html>


More information about the Twisted-Python mailing list