Add env variables to configure manifest cache#2993
Add env variables to configure manifest cache#2993kris-gaudel wants to merge 4 commits intoapache:mainfrom
Conversation
|
@kevinjqliu @Fokko @rambleraptor Please lmk what you think! |
|
@kris-gaudel I have a few questions:
|
Fokko
left a comment
There was a problem hiding this comment.
Thanks @kris-gaudel for raising this. I think it is reasonable to make this configurable. But I think we should reduce the number of changes and simplify where possible. For example, do we need PYICEBERG_MANIFEST__CACHE__ENABLED or can we set PYICEBERG_MANIFEST__CACHE__SIZE to 0 instead.
9ceb651 to
4cad1c3
Compare
f3b9f3d to
f411547
Compare
|
|
||
| result = [] | ||
| with _manifest_cache_lock: | ||
| cache = _manifest_cache |
There was a problem hiding this comment.
nit: do we need this variable here, adds a bit of noise with the change
| def reset_global_manifests_cache() -> None: | ||
| with manifest_module._manifest_cache_lock: | ||
| manifest_module._manifest_cache = manifest_module._init_manifest_cache() | ||
| clear_manifest_cache() |
There was a problem hiding this comment.
Depending on the init functionality. We can probably remove the clear since it's a no-op after calling your current init function.
| _manifest_cache_lock = threading.RLock() | ||
|
|
||
|
|
||
| def _init_manifest_cache() -> LRUCache[str, ManifestFile] | None: |
There was a problem hiding this comment.
I think we can still simplify this to:
_manifest_cache_size = Config().get_int("manifest-cache-size") or _DEFAULT_MANIFEST_CACHE_SIZE
_manifest_cache: LRUCache[str, ManifestFile] = LRUCache(maxsize=_manifest_cache_size)It someone really wants to disable caching. All I gotta do is just set this value to something like 1. The overhead here is pretty negligible. Unless there is a strong opinion for a case in which we never allocate a lrucache instance...
Closes #2952
Rationale for this change
Through discussion in issue #2325, we realized that there was a memory leak in the manifest cache. PR #2951 fixed this memory leak, but we decided that it would be best for developer experience if we developers could configure the cache for their needs.
This includes the ability to disable/enable the manifest cache, and configure its size
Are these changes tested?
Yes - unit tests are included to verify these changes
Are there any user-facing changes?
Yes:
PYICEBERG_MANIFEST__CACHE__ENABLEDcan be used to enable/disable the cache, andPYICEBERG_MANIFEST__CACHE__SIZEcan be used to configure the size of the manifest cache