You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 24, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 24, 2024. It is now read-only.
to_zarr() is extremely slow writing to high latency store #277
Many many ideas for improvements. The Zarr backend we wrote was really meant to be an MVP, it absolutely needs some work. Here's my diagnosis:
As mentioned, opening / listing each group independently is inefficient. This could be addressed here in Datatree.
Xarray sequentially initializes each group and array, then updates the user attributes. Any batching here would help. This should probably be addressed upstream in Xarray and Zarr-Python.
My approach to (2) is to rethink the Zarr-Python API for creating hierarchies. You may be interested in the discussion here: zarr-developers/zarr-python#1569
Awesome, thanks for the info! I imagine (1) would require reimplementing a good chunk of xarray's ZarrStore and other backend objects here in a way that avoids as many of these serial ops as possible?
@slevang would you mind performing the same test with xarray.core.datatree.DataTree upstream? Then I will know whether or not this issue still exists even after many changes (in xarray, datatree, and zarr). If it still exists can you please re-raise it on the xarray main repo :)
Looks like things are better but still very slow. The example in the OP now takes just over a minute on latest versions writing to GCS. DataTree.to_zarr hasn't changed so the improvement must be higher up in the stack.
I've done a little profiling, and the fundamental problem is still that we're synchronously creating each group via a separate Dataset.to_zarr call. This involves a bunch of calls to various fsspec methods to check path existence and write small attribute and metadata files. The example above writes 13 groups so that adds up quickly.
To make this significantly better, unfortunately I think we need to drop the reliance on Dataset.to_zarr and rebuild the method to write the whole group structure in one go, and then write the data.
I'll do a little more digging and reopen on xarray.
Activity
jhamman commentedon Nov 15, 2023
Many many ideas for improvements. The Zarr backend we wrote was really meant to be an MVP, it absolutely needs some work. Here's my diagnosis:
My approach to (2) is to rethink the Zarr-Python API for creating hierarchies. You may be interested in the discussion here: zarr-developers/zarr-python#1569
slevang commentedon Nov 15, 2023
Awesome, thanks for the info! I imagine (1) would require reimplementing a good chunk of
xarray'sZarrStoreand other backend objects here in a way that avoids as many of these serial ops as possible?slevang commentedon Nov 15, 2023
In the meantime, this is plenty fast for the small data case:
Takes 1s on my example above instead of 3m.
TomNicholas commentedon Sep 7, 2024
@slevang would you mind performing the same test with
xarray.core.datatree.DataTreeupstream? Then I will know whether or not this issue still exists even after many changes (in xarray, datatree, and zarr). If it still exists can you please re-raise it on the xarray main repo :)slevang commentedon Sep 8, 2024
Looks like things are better but still very slow. The example in the OP now takes just over a minute on latest versions writing to GCS.
DataTree.to_zarrhasn't changed so the improvement must be higher up in the stack.I've done a little profiling, and the fundamental problem is still that we're synchronously creating each group via a separate
Dataset.to_zarrcall. This involves a bunch of calls to variousfsspecmethods to check path existence and write small attribute and metadata files. The example above writes 13 groups so that adds up quickly.To make this significantly better, unfortunately I think we need to drop the reliance on
Dataset.to_zarrand rebuild the method to write the whole group structure in one go, and then write the data.I'll do a little more digging and reopen on xarray.