Skip to content

Commit c48dde3

Browse files
committed
feat: cache info for improved distributed performance
1 parent 432ca3c commit c48dde3

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pychunkedgraph/graph/meta.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from datetime import timedelta
23
from typing import Dict
34
from typing import List
@@ -10,6 +11,9 @@
1011

1112
from .utils.generic import compute_bitmasks
1213
from .chunks.utils import get_chunks_boundary
14+
from ..utils.redis import keys as r_keys
15+
from ..utils.redis import get_rq_queue
16+
from ..utils.redis import get_redis_connection
1317

1418

1519
_datasource_fields = ("EDGES", "COMPONENTS", "WATERSHED", "DATA_VERSION", "CV_MIP")
@@ -80,7 +84,20 @@ def custom_data(self):
8084
def ws_cv(self):
8185
if self._ws_cv:
8286
return self._ws_cv
83-
self._ws_cv = CloudVolume(self._data_source.WATERSHED)
87+
88+
try:
89+
# try reading a cached info file for distributed workers
90+
# useful to avoid md5 errors on high gcs load
91+
cache_key = f"{self.graph_config.ID}:cv_info_cached"
92+
redis = get_redis_connection()
93+
cached_info = json.loads(redis.get(cache_key))
94+
self._ws_cv = CloudVolume(self._data_source.WATERSHED, info=cached_info)
95+
except Exception:
96+
self._ws_cv = CloudVolume(self._data_source.WATERSHED)
97+
try:
98+
redis.set(cache_key, json.dumps(self._ws_cv.info))
99+
except Exception:
100+
...
84101
return self._ws_cv
85102

86103
@property

0 commit comments

Comments
 (0)