Skip to content

Commit

Permalink
dynamically increase chunk size for longer reads
Browse files Browse the repository at this point in the history
increases performance for short scans
  • Loading branch information
marvin-j97 committed Jan 25, 2024
1 parent 990b3ee commit 72fac6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions smoltable/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl Smoltable {

let readers = locality_groups_to_scan
.into_iter()
.map(|x| TableReader::new(instant, x, std::ops::Bound::Unbounded).chunk_size(100_000))
.map(|x| TableReader::new(instant, x, std::ops::Bound::Unbounded).chunk_size(64_000))
.collect::<Vec<_>>();

let mut current_row_key = None;
Expand Down Expand Up @@ -369,7 +369,7 @@ impl Smoltable {

let mut readers = locality_groups_to_scan
.into_iter()
.map(|x| TableReader::new(instant, x, std::ops::Bound::Unbounded))
.map(|x| TableReader::new(instant, x, std::ops::Bound::Unbounded).chunk_size(64_000))
.collect::<Vec<_>>();

let mut current_row_key = None;
Expand Down
28 changes: 15 additions & 13 deletions smoltable/src/table/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Reader {
pub cells_scanned_count: u64,
pub bytes_scanned_count: u64,

chunk_size: usize,
pub chunk_size: usize,
}

impl Reader {
Expand All @@ -31,10 +31,15 @@ impl Reader {
buffer: VecDeque::with_capacity(1_000),
cells_scanned_count: 0,
bytes_scanned_count: 0,
chunk_size: 1_000,
chunk_size: 10,
}
}

pub fn chunk_size(mut self, n: usize) -> Self {
self.chunk_size = n;
self
}

pub fn from_prefix(
instant: fjall::Instant,
locality_group: PartitionHandle,
Expand All @@ -45,17 +50,11 @@ impl Reader {
return Ok(None);
};

let reader =
Self::new(instant, locality_group, std::ops::Bound::Included(range)).chunk_size(16_000);
let reader = Self::new(instant, locality_group, std::ops::Bound::Included(range));

Ok(Some(reader))
}

pub fn chunk_size(mut self, n: usize) -> Self {
self.chunk_size = n;
self
}

pub fn get_range_start_from_prefix(
instant: fjall::Instant,
locality_group: &PartitionHandle,
Expand Down Expand Up @@ -85,14 +84,17 @@ impl Reader {
let mut current_range_start = self.current_range_start.clone();

loop {
// Advance range by querying chunks
match self
let collected = self
.snapshot
.range((current_range_start.clone(), Unbounded))
.into_iter()
.take(self.chunk_size)
.collect::<Result<Vec<_>, fjall::LsmError>>()
{
.collect::<Result<Vec<_>, fjall::LsmError>>();

self.chunk_size = (self.chunk_size * 2).min(64_000);

// Advance range by querying chunks
match collected {
Ok(chunk) => {
if chunk.is_empty() {
return None;
Expand Down

0 comments on commit 72fac6f

Please sign in to comment.