Replies: 1 comment
|
The expensive part here is doing consolidation after every one-file append. Since this is explicitly a Zarr v2 store, write unconsolidated during the ingestion batch and consolidate once after the loop: store_path = f"{bucket}/{store_name}"
zarr_mapper = s3_fs.get_mapper(store_path)
# Test for the Zarr v2 root metadata, not for consolidated metadata.
store_exists = s3_fs.exists(f"{store_path}/.zgroup")
if store_exists:
ds.to_zarr(
store=zarr_mapper,
mode="a",
append_dim="time",
consolidated=False,
zarr_format=2,
)
else:
ds.to_zarr(
store=zarr_mapper,
mode="w",
consolidated=False,
zarr_format=2,
encoding=time_encoding,
)Then, after all files in this run have been appended: zarr_mapper = s3_fs.get_mapper(f"{bucket}/{store_name}")
zarr.consolidate_metadata(zarr_mapper, zarr_format=2)This changes roughly 4,000 consolidation passes into one. During the batch, any code that must read the in-progress store should use The current existence check is unsafe for this pattern.
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Thank you very much for the great work on xarray. I had a question on optimizing zarr writes.
I have a large government environmental dataset that generates h5 files every day. I want to convert it to zarr and append it to my store every day. However I am finding that
ds.to_zarr(consolidated=True) is quite slow to write due to zarr-developers/zarr-python#3313I've also just tried running
zarr.consolidate_metadata(my_zarr_store)once at the end but it seemed to mess with the dimensions and collapse the time down to a small subset of the time values. Perhaps due to #11101 ?I was curious if there are any ways to improve my logic to make it faster at scale. The first time a user runs my workflow it has to download 4000 h5 files and iteratively add them to the store (they are too big to batch all together on disk) so it is quite slow to run.
My full source code is here if it helps: https://github.com/cgs-earth/ArizonaWaterObservatory/tree/main/SMAP_ETL/src
Here is an abbreviated version
These are my dependencies
I have seen #6888 and it seems like it might help but I am unclear how to apply it in my current example.
Thank you
Regards
Colton
All reactions