-
Notifications
You must be signed in to change notification settings - Fork 393
Tracking cache requests #1566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking cache requests #1566
Changes from 1 commit
49aaf3f
1a04591
dff0d30
16b27f0
1d3b0c0
b1582b4
e99b9ca
205dc06
4e2cb57
d1b5c70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ def __repr__(self) -> str: | |
cache type : {self.__class__.__name__} | ||
block size : {self.blocksize} | ||
block count : {self.nblocks} | ||
cache size : {self.size} | ||
file size : {self.size} | ||
cache hits : {self.hit_count} | ||
cache misses: {self.miss_count} | ||
total requested bytes: {self.total_requested_bytes} | ||
|
@@ -233,12 +233,20 @@ class FirstChunkCache(BaseCache): | |
name = "first" | ||
|
||
def __init__(self, blocksize: int, fetcher: Fetcher, size: int) -> None: | ||
if blocksize > size: | ||
# this will buffer the whole thing | ||
blocksize = size | ||
super().__init__(blocksize, fetcher, size) | ||
self.cache: bytes | None = None | ||
|
||
def _fetch(self, start: int | None, end: int | None) -> bytes: | ||
start = start or 0 | ||
end = end or self.size | ||
if start > self.size: | ||
logger.debug("FirstChunkCache: requested start > file size") | ||
return b"" | ||
|
||
end = min(end, self.size) | ||
|
||
if start < self.blocksize: | ||
if self.cache is None: | ||
self.miss_count += 1 | ||
|
@@ -248,12 +256,15 @@ def _fetch(self, start: int | None, end: int | None) -> bytes: | |
self.cache = data[: self.blocksize] | ||
return data[start:] | ||
self.cache = self.fetcher(0, self.blocksize) | ||
self.total_requested_bytes += self.blocksize | ||
part = self.cache[start:end] | ||
if end > self.blocksize: | ||
self.total_requested_bytes += end - self.blocksize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment: isn't the number of bytes returned by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, perhaps we are missing another variable to keep track of the |
||
part += self.fetcher(self.blocksize, end) | ||
self.hit_count += 1 | ||
return part | ||
else: | ||
self.miss_count += 1 | ||
self.total_requested_bytes += end - start | ||
return self.fetcher(start, end) | ||
|
||
|
@@ -370,8 +381,8 @@ def _read_cache( | |
start_pos = start % self.blocksize | ||
end_pos = end % self.blocksize | ||
|
||
self.hit_count += 1 | ||
if start_block_number == end_block_number: | ||
self.hit_count += 1 | ||
block: bytes = self._fetch_block_cached(start_block_number) | ||
return block[start_pos:end_pos] | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.