datacratic/soa — pull request #97 by jeremybarnes (2014-06-17 12:04:47+00:00)
Title: Rtbkit 567 zeromq block not busy poll rebased

Two main changes:

1. The message loop no longer busy polls unless it is forced to by a source. In the case that all of its sources have needsPoll = false, it will sleep on the select FDs returned by the sources and thus wake up only when necessary.
2. The ZmqEventSource now returns needsPoll = false.

It changes the semantics of the maxAddedLatency parameter to the message loop when needsPoll is false. The maxAddedLatency becomes an upper bound on the number of wakeups per second; messages that arrive faster than this will be batched up and handled in one wakeup.

This is implemented as follows. The message loop will work in "timeslices", each of which is the length of maxAddedLatency. In each timeslice it will a) block until an event is available, b) process events until there is no more work to do, and c) sleep until the beginning of the next timeslice. The blocking is indefinite; it does not end at the end of the timeslice so it does not cause any extra wakeups. The sleeping only occurs when there is some idle time in the message loop; if the loop is busy the entire timeslice it will not occur.

These changes expose shutdown ordering issues in some client code, notably in RTBkit which has a separate set of patches addressing those issues.