-
Notifications
You must be signed in to change notification settings - Fork 126
[pr] Add an option to run the cleanup algorithm optimized for low memory usage #47
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lib/cache/cache_fs.js
Outdated
|
|
||
| cleanup_low_mem(dryRun = true, expireDuration, minFileAccessTime, maxCacheSize) { | ||
|
|
||
| const self = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This self isn't needed as all its usages could use this directly as they are contained within arrow functions.
lib/cache/cache_fs.js
Outdated
| } | ||
|
|
||
| cleanup_fast(dryRun = true, expireDuration, minFileAccessTime, maxCacheSize) { | ||
| const self = this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't seem to be able to find an instance of self here that couldn't just use this directly. There are no function expressions, only arrow functions, which will not have their own context, and can use this. This line should be safe to delete if you change the self usages to this.
|
Fixed the |
|
My general question/feedback: I would prefer that we just have one way of doing things, instead of adding this as a "low memory" option .. is the algorithm so much slower that we need to have a "fast" path? |
|
The low memory algorithm uses 2 passes, but each pass is about the same time as the "fast" method. So it takes about twice the time. I'll take the old way out, if you think that's an acceptable increase. Realistically, this will be running in daemon mode and you'll never really know the difference anyway. |
|
I might be missing something but it seems like you could combine the passes so you only read the dir once - if the file was deleted based on age, delete and continue to the next. Otherwise, consider it for deletion based on maxSize. |
|
The first pass is mainly to get the total CacheSize. Is there a better way to get that? |
|
right, that's required. No there isn't a better way to do that. So anyhow, even with the two dir passes, this should be fine as the default/only code path for cleanup. |
The memory optimized cleanup algorithm breaks the process down into two passes:
On the first pass, any expired files are detected and unlinked in the same block.
For the second pass, we return immediately if Max Cache Size is unused, or already satisfied. Otherwise, we maintain a list that will never exceed the difference between Total Cache Size and Max Cache Size items. This list is sorted such that it will contain the most LRU items at the end of execution. Items in the list are then deleted.
Memory Profiling with ~1million files: