Skip to content

Commit

Permalink
Record seek_distance metrics whether or not the seek triggers a reset (
Browse files Browse the repository at this point in the history
…#800)

By always recording the length of a seek attempt, we should get a better picture of the read pattern. The `out_of_order` metric can already be used to determine whether or not the seek could be performed without resetting the prefetcher.

Signed-off-by: Alessandro Passaro <[email protected]>
  • Loading branch information
passaro authored Mar 7, 2024
1 parent 0fbc8e9 commit d61d688
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions mountpoint-s3/src/prefetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ where
async fn try_seek_forward(&mut self, offset: u64) -> Result<bool, PrefetchReadError<Client::ClientError>> {
assert!(offset > self.next_sequential_read_offset);
let total_seek_distance = offset - self.next_sequential_read_offset;
histogram!("prefetch.seek_distance", "dir" => "forward").record(total_seek_distance as f64);

let Some(current_task) = self.current_task.as_mut() else {
// Can't seek if there's no requests in flight at all
return Ok(false);
Expand Down Expand Up @@ -507,15 +509,14 @@ where
self.next_sequential_read_offset += part.len() as u64;
self.backward_seek_window.push(part);
}

histogram!("prefetch.seek_distance", "dir" => "forward").record(total_seek_distance as f64);

Ok(true)
}

fn try_seek_backward(&mut self, offset: u64) -> Result<bool, PrefetchReadError<Client::ClientError>> {
assert!(offset < self.next_sequential_read_offset);
let backwards_length_needed = self.next_sequential_read_offset - offset;
histogram!("prefetch.seek_distance", "dir" => "backward").record(backwards_length_needed as f64);

let Some(parts) = self.backward_seek_window.read_back(backwards_length_needed as usize) else {
trace!("seek failed: not enough data in backwards seek window");
return Ok(false);
Expand All @@ -529,9 +530,6 @@ where
}
self.current_task = Some(request);
self.next_sequential_read_offset = offset;

histogram!("prefetch.seek_distance", "dir" => "backward").record(backwards_length_needed as f64);

Ok(true)
}
}
Expand Down

0 comments on commit d61d688

Please sign in to comment.