Skip to content

Commit

Permalink
Make run_pending_tasks to evict more entries from the cache at once
Browse files Browse the repository at this point in the history
- Disable the eviction batch size when the eviction listener is not set to the cache.
  - So single `run_pending_tasks` call should remove all entries that can be evicted
    from the cache.
- Add a hard-coded maintenance task timeout duration.
  - When the eviction listener is set, `run_pending_tasks` should stop (return) after
    the maintenance task timeout is elapsed.
  - This is a safe-guard to prevent the maintenance task from running long time when
    the user wrote a slow eviction listener.
  - In older versions, the batch size was used to limit the time spent on the
    maintenance task.
  - Not that `run_pending_tasks` checks the timeout only after processing a batch
    of entries, so `run_pending_tasks` can run longer than the timeout duration.
- Reduce the size of the read op and write op channels.
  • Loading branch information
tatsuya6502 committed Apr 14, 2024
1 parent 1d2af53 commit e222fb0
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 172 deletions.
16 changes: 12 additions & 4 deletions src/common/concurrent/constants.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
pub(crate) const MAX_SYNC_REPEATS: usize = 4;
pub(crate) const PERIODICAL_SYNC_INITIAL_DELAY_MILLIS: u64 = 300;

pub(crate) const READ_LOG_FLUSH_POINT: usize = 512;
pub(crate) const READ_LOG_SIZE: usize = READ_LOG_FLUSH_POINT * (MAX_SYNC_REPEATS + 2);
pub(crate) const READ_LOG_FLUSH_POINT: usize = 64;
pub(crate) const READ_LOG_SIZE: usize = READ_LOG_FLUSH_POINT * (MAX_SYNC_REPEATS + 2); // 384

pub(crate) const WRITE_LOG_FLUSH_POINT: usize = 512;
pub(crate) const WRITE_LOG_SIZE: usize = WRITE_LOG_FLUSH_POINT * (MAX_SYNC_REPEATS + 2);
pub(crate) const WRITE_LOG_FLUSH_POINT: usize = 64;
pub(crate) const WRITE_LOG_SIZE: usize = WRITE_LOG_FLUSH_POINT * (MAX_SYNC_REPEATS + 2); // 384

// TODO: Calculate the batch size based on the number of entries in the cache (or an
// estimated number of entries to evict)
pub(crate) const EVICTION_BATCH_SIZE: usize = WRITE_LOG_SIZE;
pub(crate) const INVALIDATION_BATCH_SIZE: usize = WRITE_LOG_SIZE;

/// The default timeout duration for the `run_pending_tasks` method.
pub(crate) const DEFAULT_RUN_PENDING_TASKS_TIMEOUT_MILLIS: u64 = 100;

#[cfg(feature = "sync")]
pub(crate) const WRITE_RETRY_INTERVAL_MICROS: u64 = 50;
4 changes: 2 additions & 2 deletions src/common/concurrent/housekeeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ impl Default for Housekeeper {

impl Housekeeper {
pub(crate) fn should_apply_reads(&self, ch_len: usize, now: Instant) -> bool {
self.should_apply(ch_len, READ_LOG_FLUSH_POINT / 8, now)
self.should_apply(ch_len, READ_LOG_FLUSH_POINT, now)
}

pub(crate) fn should_apply_writes(&self, ch_len: usize, now: Instant) -> bool {
self.should_apply(ch_len, WRITE_LOG_FLUSH_POINT / 8, now)
self.should_apply(ch_len, WRITE_LOG_FLUSH_POINT, now)
}

#[inline]
Expand Down
Loading

0 comments on commit e222fb0

Please sign in to comment.