don't fetch readv chunks that we have reason to believe are already in prefetch buffers.  no longer need to order the prefetch requests either.
This commit is contained in:
Robey Pointer 2006-07-25 17:29:47 -07:00
parent c24db3e38c
commit c731a077fb
1 changed files with 12 additions and 15 deletions

View File

@ -388,23 +388,20 @@ class SFTPFile (BufferedFile):
@since: 1.5.4 @since: 1.5.4
""" """
# put the offsets in order, since we depend on that for determining
# when the reads have finished.
self.sftp._log(DEBUG, 'readv(%s, %r)' % (util.hexify(self.handle), chunks)) self.sftp._log(DEBUG, 'readv(%s, %r)' % (util.hexify(self.handle), chunks))
ordered_chunks = list(chunks)
ordered_chunks.sort(lambda x, y: cmp(x[0], y[0]))
# break up anything larger than the max read size read_chunks = []
if len([size for offset, size in ordered_chunks if size > self.MAX_REQUEST_SIZE]) > 0: for offset, size in chunks:
read_chunks = [] # don't fetch data that's already in the prefetch buffer
for offset, size in ordered_chunks: if self._data_in_prefetch_buffers(offset):
while size > 0: continue
chunk_size = min(size, self.MAX_REQUEST_SIZE)
read_chunks.append((offset, chunk_size)) # break up anything larger than the max read size
offset += chunk_size while size > 0:
size -= chunk_size chunk_size = min(size, self.MAX_REQUEST_SIZE)
else: read_chunks.append((offset, chunk_size))
read_chunks = ordered_chunks offset += chunk_size
size -= chunk_size
self._start_prefetch(read_chunks) self._start_prefetch(read_chunks)
# now we can just devolve to a bunch of read()s :) # now we can just devolve to a bunch of read()s :)