Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(456)

Issue 145220043: call_at/call_later with Timer cancellation can result in (practically) unbounded memory usage

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 1 month ago by chatgris
Modified:
11 years, 1 month ago
Reviewers:
gvrpython, yselivanov, GvR
Visibility:
Public.

Description

This patch is intended to fix http://bugs.python.org/issue22448. Option b) was implemented. The measure to indicate that scheduled event filtering (to remove cancelled events) needs to be performed is 1) There are at least 100 events scheduled. This prevents needless reheapifying if there are only a handful of events. 2) More than 50% of scheduled events are cancelled. The use of a percentage ensures that a list of 10,000 events isn't reheaped for some small fixed number of cancelled events. Otherwise 50% was just chosen as it seemed a reasonable measure. Note that _cancel_count is not always completely accurate, nor does it need to be: - It may be possible for events that are _ready to be cancelled, and it may be possible for race conditions to occur if two threads are cancelling the same timer handle at the same time. - Other threads may cancel events while _scheduled events are being rebuilt. Note that I added a condition (events.py) to avoid repeated cancellation messing up the _cancel_count. Once I added that, I thought it would make sense to include the rest of the method in the condition. This has the added benefit of the string representation of the arguments not getting wiped on repeated cancellation. test_base_events.py and test_events.py were both updated to test these changes.

Patch Set 1 #

Patch Set 2 : pep8 line length #

Patch Set 3 : Test that cancelled events at head of scheduled list are accounted for #

Patch Set 4 : Moved double cancellation test to debug test #

Patch Set 5 : Removed blank indentation #

Patch Set 6 : Better documentation for test case #

Patch Set 7 : Removed redundant leading spaces on blank lines #

Total comments: 2

Patch Set 8 : Demonstrates options on how to stop overcounting events + misc feedback fixes #

Patch Set 9 : Track scheduled handles by flag inline #

Total comments: 13

Patch Set 10 : Various nits fixed #

Patch Set 11 : Test code that ties into new constants fixed #

Total comments: 5

Patch Set 12 : Minor fixes based on latest feedback #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+145 lines, -26 lines) Patch
M asyncio/base_events.py View 1 2 3 4 5 6 7 8 9 10 11 6 chunks +37 lines, -7 lines 1 comment Download
M asyncio/events.py View 1 2 3 4 5 6 7 8 9 10 11 5 chunks +20 lines, -9 lines 0 comments Download
M tests/test_base_events.py View 1 2 3 4 5 6 7 8 9 10 11 3 chunks +77 lines, -7 lines 0 comments Download
M tests/test_events.py View 1 2 3 4 5 6 7 8 9 1 chunk +11 lines, -3 lines 0 comments Download

Messages

Total messages: 24
chatgris
11 years, 1 month ago (2014-09-20 21:54:07 UTC) #1
yselivanov
https://codereview.appspot.com/145220043/diff/110001/asyncio/base_events.py File asyncio/base_events.py (right): https://codereview.appspot.com/145220043/diff/110001/asyncio/base_events.py#newcode148 asyncio/base_events.py:148: self._cancel_count = 0 Maybe we can come up with ...
11 years, 1 month ago (2014-09-20 22:42:44 UTC) #2
chatgris
On 2014/09/20 22:42:44, yselivanov wrote: > https://codereview.appspot.com/145220043/diff/110001/asyncio/base_events.py > File asyncio/base_events.py (right): > > https://codereview.appspot.com/145220043/diff/110001/asyncio/base_events.py#newcode148 > ...
11 years, 1 month ago (2014-09-20 23:00:42 UTC) #3
GvR
Thanks, this is a good start. Some remarks in addition to Yuri's review: - You ...
11 years, 1 month ago (2014-09-21 02:30:59 UTC) #4
chatgris
On 2014/09/21 02:30:59, GvR wrote: > Thanks, this is a good start. Some remarks in ...
11 years, 1 month ago (2014-09-21 18:57:29 UTC) #5
chatgris
Note: Apologies for the terrible formatting of my last post, I didn't realize it automatically ...
11 years, 1 month ago (2014-09-21 18:59:03 UTC) #6
GvR
On 2014/09/21 18:59:03, chatgris wrote: > Note: Apologies for the terrible formatting of my last ...
11 years, 1 month ago (2014-09-22 18:14:30 UTC) #7
chatgris
On 2014/09/22 18:14:30, GvR wrote: > On 2014/09/21 18:59:03, chatgris wrote: > > Note: Apologies ...
11 years, 1 month ago (2014-09-23 16:32:23 UTC) #8
yselivanov
The patch is getting better and better! I'm +1 for B1 strategy you guys have ...
11 years, 1 month ago (2014-09-23 16:56:05 UTC) #9
GvR
I'm with Yuri's comments (except where I explicitly disagree :-). Here are some nits. https://codereview.appspot.com/145220043/diff/150001/asyncio/base_events.py ...
11 years, 1 month ago (2014-09-23 17:07:04 UTC) #10
chatgris
Added new patch set to fix nits, will reply to a few specific issues in ...
11 years, 1 month ago (2014-09-23 18:14:25 UTC) #11
chatgris
> https://codereview.appspot.com/145220043/diff/150001/asyncio/base_events.py#newcode1004 > asyncio/base_events.py:1004: # Remove delayed calls that were cancelled if their > number ...
11 years, 1 month ago (2014-09-23 18:16:54 UTC) #12
chatgris
I just realized that the tests I changed to tie into the new constants is ...
11 years, 1 month ago (2014-09-23 18:43:27 UTC) #13
chatgris
On 2014/09/23 18:43:27, chatgris wrote: > I just realized that the tests I changed to ...
11 years, 1 month ago (2014-09-23 19:20:40 UTC) #14
yselivanov
Looks good, aside from just couple of really small notes. I also like how you ...
11 years, 1 month ago (2014-09-23 19:41:02 UTC) #15
chatgris
On 2014/09/23 19:41:02, yselivanov wrote: > https://codereview.appspot.com/145220043/diff/160005/asyncio/base_events.py#newcode44 > asyncio/base_events.py:44: # cancelled handles is performed > ...
11 years, 1 month ago (2014-09-23 20:04:10 UTC) #16
yselivanov
Looks good now.
11 years, 1 month ago (2014-09-24 00:13:00 UTC) #17
GvR
Yuri, if you're happy with it, I have no further comments. Can you commit this ...
11 years, 1 month ago (2014-09-25 01:50:23 UTC) #18
yselivanov
I was in the middle of committing the patch when I saw one more thing ...
11 years, 1 month ago (2014-09-25 02:55:48 UTC) #19
GvR
On 2014/09/25 02:55:48, yselivanov wrote: > I was in the middle of committing the patch ...
11 years, 1 month ago (2014-09-25 03:16:59 UTC) #20
chatgris
On 2014/09/25 03:16:59, GvR wrote: > On 2014/09/25 02:55:48, yselivanov wrote: > > I was ...
11 years, 1 month ago (2014-09-25 15:07:17 UTC) #21
yselivanov
Joshua, I've just committed the patch to CPython and tulip: - https://hg.python.org/cpython/rev/2a868c9f8f15 - https://hg.python.org/cpython/rev/a6aaacb2b807 - ...
11 years, 1 month ago (2014-09-25 16:11:54 UTC) #22
gvrpython
Sounds good to me. It's possible that the difference between A and B is due ...
11 years, 1 month ago (2014-09-25 16:12:31 UTC) #23
gvrpython
11 years, 1 month ago (2014-09-25 16:28:00 UTC) #24
Thanks Yuri and Joshua!! This was a very useful exercise. On Thu, Sep 25, 2014 at 9:11 AM, <yselivanov@gmail.com> wrote: > Joshua, I've just committed the patch to CPython and tulip: > > - https://hg.python.org/cpython/rev/2a868c9f8f15 > - https://hg.python.org/cpython/rev/a6aaacb2b807 > - > https://code.google.com/p/tulip/source/detail?r= > df3fa0556765e51ed06551af6fc2e1f1e0ec18a0 > > Thank you for the patch and for your patience during the code review! > > https://codereview.appspot.com/145220043/ > -- --Guido van Rossum (python.org/~guido) 
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b