Skip to content

Give Memory.reduce_size() items_limit and age_limit options#1200

Merged
tomMoral merged 13 commits intojoblib:masterfrom
jwodder:gh-1183
Jun 1, 2023
Merged

Give Memory.reduce_size() items_limit and age_limit options#1200
tomMoral merged 13 commits intojoblib:masterfrom
jwodder:gh-1183

Conversation

@jwodder
Copy link
Copy Markdown
Contributor

@jwodder jwodder commented Jul 1, 2021

Closes #1183.

Not really sure how to write a test for this; advice appreciated.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 1, 2021

Codecov Report

Patch coverage: 98.41% and project coverage change: -0.10 ⚠️

Comparison is base (2303143) 94.90% compared to head (de764ea) 94.81%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1200      +/-   ##
==========================================
- Coverage   94.90%   94.81%   -0.10%     
==========================================
  Files          44       44              
  Lines        7308     7361      +53     
==========================================
+ Hits         6936     6979      +43     
- Misses        372      382      +10     
Impacted Files Coverage Δ
joblib/memory.py 95.41% <87.50%> (-0.20%) ⬇️
joblib/_store_backends.py 92.01% <100.00%> (+0.43%) ⬆️
joblib/test/test_memory.py 98.55% <100.00%> (+0.07%) ⬆️

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jwodder jwodder changed the title Give Memory a files_limit option Give Memory files_limit and age_limit options Aug 10, 2021
Copy link
Copy Markdown
Contributor

@tomMoral tomMoral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

Thanks a lot for the PR and sorry for the long delay in the review. I feel this would be a nice addition but not totally sure about the API. Adding all these arguments (we could think of others I am sure) can make it complicated to maintain a simple usage, which is the aim of joblib. I would be in favor of keeping this argument only in Memory.reduce_size.

I did a couple comments and to move forward, I think adding some tests would be required and also adding a simple usage example in the Memory documentation.

joblib/memory.py Outdated
def __init__(self, location=None, backend='local', cachedir=None,
mmap_mode=None, compress=False, verbose=1, bytes_limit=None,
backend_options=None):
files_limit=None, age_limit=None, backend_options=None):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is a good idea to add this at the class instantiation level as this is not directly enforce by Memory.
This actually makes it confusing in the doc (cf the Note) so maybe a better way would be to directly pass this in reduce_size, so it is clear it is only enforced by calling reduce_size. And if we go with this, maybe it would be a good idea to deprecate bytes_limit.

Not sure about that at all, maybe a better way would be to implement a Thread that checks the limit, but this feels a bit brittle and can add a lot of complexity.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have moved these arguments to reduce_size(). I leave it to you to take care of bytes_limit.

@jwodder
Copy link
Copy Markdown
Contributor Author

jwodder commented Nov 2, 2021

@tomMoral I've made your requested changes (including changing age_limit to a timedelta; not sure why I can't reply to that comment).

I agree that tests should be added; however, I'm not sure how exactly to write them and would appreciate advice.

@jwodder jwodder changed the title Give Memory files_limit and age_limit options Give Memory.reduce_size() items_limit and age_limit options Nov 2, 2021
@tomMoral
Copy link
Copy Markdown
Contributor

tomMoral commented Nov 2, 2021

@tomMoral I've made your requested changes (including changing age_limit to a timedelta; not sure why I can't reply to that comment).

Thanks a lot for the modifications.

I agree that tests should be added; however, I'm not sure how exactly to write them and would appreciate advice.

For the tests, I would put some results in cache, then check that they are indeed cached, reduce_size with some harsh limit (age_limits/item_limits=0...) and check that the results are not in cache anymore.
You can use the check_call_in_cache helper to check if a specific call is in cache:

cached_foo = mem.cache(foo)
cached_foo.check_call_in_cache(x)
>>> False
cached_foo(x)
cached_foo.check_call_in_cache(x)
>>> True

Copy link
Copy Markdown
Contributor

@tomMoral tomMoral left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thx for proposing this @jwodder

I just need to add an entry in the change log and we should be good to merge this feature.
I will open another PR to deprecate the bytes_limit from __init__ as this will make clearer that the limits need to be enforced by calling reduce_size manually.

@tomMoral tomMoral merged commit d38b002 into joblib:master Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wishlist: more flexible control (not just by size) for clean up

3 participants