From d61d688f93ffb3f35fa1019a0b36f6c2e8228107 Mon Sep 17 00:00:00 2001 From: Alessandro Passaro Date: Thu, 7 Mar 2024 11:16:43 +0000 Subject: [PATCH] Record seek_distance metrics whether or not the seek triggers a reset (#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 --- mountpoint-s3/src/prefetch.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/mountpoint-s3/src/prefetch.rs b/mountpoint-s3/src/prefetch.rs index 8d28102cc..cf653f907 100644 --- a/mountpoint-s3/src/prefetch.rs +++ b/mountpoint-s3/src/prefetch.rs @@ -456,6 +456,8 @@ where async fn try_seek_forward(&mut self, offset: u64) -> Result> { 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); @@ -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> { 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); @@ -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) } }