Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Integrate message reading into twisted reactor loop #66
During work with txZMQ I met the case when fast incoming messages stream with not so fast message processing functions prevents twisted reactor's loop from resuming because loop reading messages in
I've made some simple throughput measurements sending 1M short 18 byte messages and counting them at the receiver side and got following numbers for receive rate:
For 180K byte messages rates are almost equal ~25K messages per second.
This impact may be reduced by reading several messages at once in read loop limiting by the time spent in cycle before yielding to reactor. However the whole point of this pull request is to make message receiving and processing functions to properly cooperate with other participants in twisted service and to prevent them from consuming all available resources effectively blocking event loop. Also this patch makes possible synchronization of sending and receiving rates by means of hwm, so that sender will not overload receiver.
As for message processing functions out of the event loop I don't quite understand what do you mean unless you speak of offloading them to other threads or processes because everything in Twisted is driven by the event loop.
I have 2 suggestion on how to reduce performance impact while keeping possibility to cooperate with reactor:
The first is easier for consumers but the second is more explicit and more in line with how Twisted handles similar problems.