[Twisted-Python] Cause epollreactor to busyspin

Glyph glyph at twistedmatrix.com
Wed Apr 20 20:57:06 MDT 2016


> On Apr 20, 2016, at 10:37, Tim Hughes <thughes at thegoldfish.org> wrote:
> 
> Hi All,
> 
> I have a latency sensitive application that gets affected when it is moved between cores or the system has to wake from idling.

Can you explain "gets affected" in more detail?  If moving between cores is the issue, could you set its CPU affinity?

> I would like to run the thread in as tight a loop as possible and to do this i need to cause epollreactor to busyspin on receiving data.

I am very curious about your application now :)

> I have worked out how to do it by editing the twisted code directly by hard coding the value of `timeout` to be 0 at this location in the code https://github.com/twisted/twisted/blob/f074ba3d5083aa1503abcf194aece327e7f84805/twisted/internet/epollreactor.py#L370

> Is it possible to actually set this on the reactor in a more sensible way so I don't need to patch the twisted codebase. ? Below is basically what I am doing.

You can achieve this with a tiny bit of extra overhead by doing something like this:

def cant_sleep_clown_will_eat_me():
    reactor.callLater(0, cant_sleep_clown_will_eat_me)
cant_sleep_clown_will_eat_me()

Does this actually improve your latency?

-glyph



More information about the Twisted-Python mailing list