<div dir="ltr"><div><div>Yeah, so the pyftp fix is to keep track of how many timers were cancelled, and if the number exceeds a threshold it just recreates the heap, something like<br><br></div>heap = [x for x in heap if not x.cancelled]<br>

</div>heapify(heap)<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Mar 26, 2014 at 3:02 PM, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net" target="_blank">solipsis@pitrou.net</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Wed, 26 Mar 2014 23:57:27 +0200<br>
Marko Rauhamaa <<a href="mailto:marko@pacujo.net">marko@pacujo.net</a>> wrote:<br>
> Antoine Pitrou <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>>:<br>
><br>
> > Marko Rauhamaa <<a href="mailto:marko@pacujo.net">marko@pacujo.net</a>> wrote:<br>
> >> In my experience, networking entities typically start a timer at each<br>
> >> interaction and cancel the pending one. So you have numerous timers<br>
> >> that virtually never expire. You might have 100 interactions per<br>
> >> second, each canceling and restarting a 10-minute timer.<br>
> ><br>
> > Each individual heapq operation (push or pop) will be O(log n). That's<br>
> > not different from a balanced search tree (although of course the<br>
> > constant multiplier may vary).<br>
><br>
> Yes, but if I have 1000 connections with one active timer each. The size<br>
> of my sorted tree is 1000 timer objects. There are typically no expiries<br>
> to react to.<br>
><br>
> If the canceled timer lingers in the heapq till its expiry (in 10<br>
> minutes), the size is 100 * 10 * 60 = 60,000. The CPU has to wake up<br>
> constantly to clear the expired timers.<br>
<br>
</div>Ideally, I think you should be able to replace the cancelled item with<br>
the last item in the heap and then fix the heap in logarithmic time,<br>
but the heapq API doesn't seem to provide a way to do this.<br>
<br>
Regards<br>
<span class="HOEnZb"><font color="#888888"><br>
Antoine.<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" target="_blank">https://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">https://mail.python.org/mailman/options/python-dev/guido%40python.org</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div>