[Twisted-Python] Performance issue in reactor.callLater
behnel_ml at gkec.informatik.tu-darmstadt.de
Mon Sep 6 09:43:04 EDT 2004
I'm running a network simulator on top of Twisted and that made me realize a heavy performance bottleneck.
When I'm simulating a larger number of network nodes each of which uses two or three delayed calls, that adds up and then adding and cancelling calls becomes /really/ expensive. We are talking about ~ one millisecond per add and even a few milliseconds per cancel.
The problem is the implementation that uses a linear list. A heap would be /much/ more appropriate. But especially the cancel could be spead up by factors by not actually removing the object but just setting a flag that it was canceled. The canceled DelayedCall objects would then be filtered out when looking for the next delay.
I already implemented that in my simulator when I was trying to eliminate the calls to dc.cancel(). Works perfectly well, but I'd rather see Twisted scale better itself.
Are there any objections to replacing the current implementation?
Otherwise I'd just send a patch to the list as soon as I have integrated my version into the respective classes.
More information about the Twisted-Python