Add env variables to configure manifest cache#2993
Add env variables to configure manifest cache#2993kris-gaudel wants to merge 9 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.
f3b9f3d to
f411547
Compare
thomas-pfeiffer
left a comment
There was a problem hiding this comment.
Additional remark:
I suggest to add paragraph to /mkdocs/docs/configuration.md to document the new configuration option. Something like:
## Manifest Caching
PyIceberg by default caches the Iceberg Manifest files locally.
By default up to the `128` least recently used Manifests are cached, leveraging up to approx. X MB of memory.
(Indicative calculation only. X MB in total = 128 Manifests * average size of X KB per Manifest. Your Manifest's sizes may be different.)
The maximum cache size can be customised by setting `PYICEBERG_MANIFEST_CACHE_SIZE` environment variable to a positive number.
To deactivate the Manifest caching completely, set the max. cache size to `0`;
To achieve an unlimited / unbound Manifest cache, set the max. cache size to `math.inf` or something comparable.@kevinjqliu / @Fokko / @kris-gaudel - Do you have a rough ball-park number for the size of the cached Manifests? I would like to give a rough indication to users how much memory the cache may consume. Or is that a bad idea?
|
Sorry for the late responses, it was a hectic week. I will update the docs and address PR comments early this week |
f64d6ca to
1628ea0
Compare
d864368 to
981aadf
Compare
| PyIceberg caches `ManifestFile` objects locally and uses an LRU policy to bound the cache size. By default, up to `128` | ||
| manifest entries are retained. | ||
|
|
||
| You can change the cache size with the `PYICEBERG_MANIFEST_CACHE_SIZE` environment variable: |
There was a problem hiding this comment.
I think it'd be helpful to frame this more as a config and configs are tunable by the environment variable or the .pyiceberg.yaml. I guess this kind of just makes it seem like you can only tune this number with an environment variable.
Going off of what you have below:
Config().get_int("manifest-cache-size")
| ) | ||
|
|
||
| # Lock for thread-safe cache access | ||
| # Lock for thread-safe cache access. |
There was a problem hiding this comment.
nit: on the cosmetic comment change here
| # Lock for thread-safe cache access | ||
| # Lock for thread-safe cache access. | ||
| _manifest_cache_lock = threading.RLock() | ||
| _manifest_cache: LRUCache[str, ManifestFile] | dict[str, ManifestFile] = ( |
There was a problem hiding this comment.
Do we even need this map | lru complexity if you're returning early below?
| file = io.new_input(manifest_list) | ||
| manifest_files = list(read_manifest_list(file)) | ||
|
|
||
| if _manifest_cache_size == 0: |
There was a problem hiding this comment.
We will see a cahce failure if someone incidentally sets cache to negative value
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_SIZEcan be used to configure the size of the manifest cache