jamwt/diesel — pull request #68 by dowski (2013-04-23 13:51:54+00:00)
Title: Don't lazily remove timers

This was biting us because timers that were set to fire far in the
future (many seconds at least) were piling up in the `.timers` deque in
the hub even while they were being deleted from the `.timer_map`. This was
causing the hub to spend too much time clearing them out and it was
falling behind on actual timers it was supposed to service and not being
able to recover.

This change moves the canonical storage of `Timer`s in `.timers` to a list.
This is better for deleting cancelled timers (`.remove()` on a list is
twice as fast as `.remove()` on a deque). The `.timers` list is kept in
reverse sorted order so that `Timer`s that are due can be popped off the
end.

This is much closer to the original design, before I started making changes last
week. The main differences are list vs. deque, in-place sort of `.timers` using `operator.attrgetter` and no more Python level `__cmp__` function (which was
killing us when sorting and removing).