Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d646442
Stream hf:// files from the CDN to avoid Hub rate limits (#664)
tristan-deep Oct 26, 2026
62e40e6
Validate ZEA_MAX_CONCURRENT_REQUESTS and keep the retry log off the e…
tristan-deep Oct 26, 2026
bde3508
Redact signed URLs in fsspec's HTTP debug log
tristan-deep Oct 26, 2026
1f4122d
fixed potential burst of requests on ttl expiry
Louisvh Oct 29, 2026
4bb3aee
Merge branch 'main' into feature/hf-cdn-streaming
tristan-deep Nov 2, 2026
d3b0c59
improve fetching of small chunks
tristan-deep Nov 2, 2026
e465a91
Keep large chunks on the merged path and make read_at thread-safe
tristan-deep Nov 2, 2026
d378820
Merge remote-tracking branch 'origin/main' into feature/hf-cdn-streaming
tristan-deep Nov 4, 2026
cd2bcb6
Drop cached CDN URLs on upload and reuse branch URLs only as long as …
tristan-deep Nov 4, 2026
206600e
Ask the Hub at most once per cooldown when a URL refresh gives nothin…
tristan-deep Nov 4, 2026
9e9954e
Keep using the current URL when its early refresh fails
tristan-deep Nov 4, 2026
a138178
Redact signed URLs in the errors of failed range requests
tristan-deep Nov 4, 2026
0a2ba87
Draw no progress bar for reads below MIN_BYTES
tristan-deep Nov 4, 2026
68c62c7
Check the chunk cache with a stat in pending_bytes
tristan-deep Nov 4, 2026
7b3d0ec
Fetch the blocks of a small read concurrently
tristan-deep Nov 4, 2026
3f43635
Merge ranges only while a request downloads no more gap bytes than ch…
tristan-deep Nov 4, 2026
afcc0ef
Keep one block cache per streamed file instead of two
tristan-deep Nov 4, 2026
dca16d0
Ask the stream whether it keeps the blocks it reads
tristan-deep Nov 4, 2026
dcd792d
Share the on-disk cache helpers of the Hub listing and the CDN URLs
tristan-deep Nov 4, 2026
3fcd16b
Merge branch 'main' into feature/hf-cdn-streaming
tristan-deep Nov 4, 2026
08f275f
Merge branch 'main' into feature/hf-cdn-streaming
swpenninga Nov 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fetch the blocks of a small read concurrently
fetch_small read each sub-block chunk with a blocking read_at, so a small read touching
chunks in N blocks cost N round trips one after another. The blocks it is missing are now
fetched together first, and the chunks are then served from them.
  • Loading branch information
tristan-deep committed Nov 4, 2026
commit 7b3d0ec7abcc18070a278d1fb9cc6fe497831600
21 changes: 21 additions & 0 deletions tests/data/test_hf_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,24 @@ def test_small_reads_draw_no_progress_bar(small_cdn, monkeypatch):
for _ in range(2):
chunk_reader.read(remote[RAW], 0, remote._chunk_fetcher, progress=True)
tqdm_mock.assert_not_called()


def test_small_reads_fetch_their_blocks_concurrently(tmp_path, hub):
"""A small read whose chunks lie in several blocks fetches those blocks together."""
path = _write(tmp_path / "x.hdf5", _structured())
server = _CountingServer(tmp_path, latency=0.05)
hub.location, hub.size = server.url + path.name, path.stat().st_size
try:
block = 64 << 10
with File(HF_PATH, progress=False, cache=False, block_size=block) as remote:
dset = remote[RAW]
chunks = [dset.id.get_chunk_info(i) for i in (3, 4)]
assert all(chunk.size < block for chunk in chunks)
assert len({chunk.byte_offset // block for chunk in chunks}) == 2
server.peak, before = 0, server.count
got = chunk_reader.read(dset, slice(3, 5), remote._chunk_fetcher)
with File(path) as local:
np.testing.assert_array_equal(got, local[RAW][3:5])
assert server.count - before == 2 and server.peak == 2
finally:
server.close()
22 changes: 19 additions & 3 deletions zea/data/chunk_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,31 @@ def fetch_small(
transmit stored in a 7 MB chunk) go through :meth:`fetch`, as one request instead of a
request per block.
"""
if self.blocks is None:
blocks = self.blocks
if blocks is None:
return self.fetch(ranges, on_bytes)
out: list[bytes | None] = [None] * len(ranges)
large = [i for i, (_, size) in enumerate(ranges) if size >= self.blocks.blocksize]
block_size = blocks.blocksize
large = [i for i, (_, size) in enumerate(ranges) if size >= block_size]
for i, data in zip(large, self.fetch([ranges[i] for i in large], on_bytes)):
out[i] = data

# Fetch the blocks of the small chunks together, so a read spread over many blocks
# costs one round trip instead of one per block. read_at keeps them for the reads below.
starts = {
start
for i, (offset, size) in enumerate(ranges)
if out[i] is None
for start in range(offset - offset % block_size, offset + size, block_size)
}
if len(starts) > 1:
workers = min(len(starts), MAX_CONCURRENT_REQUESTS)
with ThreadPoolExecutor(max_workers=workers) as pool:
list(pool.map(lambda start: blocks.read_at(start, 1), sorted(starts)))

for i, (offset, size) in enumerate(ranges):
if out[i] is None:
out[i] = self.blocks.read_at(int(offset), int(size))
out[i] = blocks.read_at(int(offset), int(size))
if on_bytes is not None:
on_bytes(int(size))
return cast(list[bytes], out)
Expand Down