Skip to content

Commit 112fec0

Browse files
authored
Server: expired message cleaner cleanup (#1167)
Simplifies some of the timing code on the expired message cleaner. No more 2 level check for slow vs idle. Just sleep big when the expired row count is less than the batch size.
2 parents d5b7107 + 6602111 commit 112fec0

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

server/svix-server/src/expired_message_cleaner.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,8 @@ pub async fn expired_message_cleaner_loop(pool: &DatabaseConnection) -> Result<(
123123
tracing::info!("No payloads pending expiry found in `message` table. Skipping the cleaner for this table.");
124124
}
125125

126-
// When no rows have been updated, widen the interval.
126+
// When fewer rows than the batch size have been updated, take a nap for this long.
127127
const IDLE: Duration = Duration::from_secs(60 * 60 * 12);
128-
// When the affected row count dips below this, switch to the `SLOWING` interval.
129-
const SLOWING_THRESHOLD: u64 = 5_000;
130-
const SLOWING: Duration = Duration::from_secs(60 * 60 * 12);
131128
const ON_ERROR: Duration = Duration::from_secs(10);
132129
const BATCH_SIZE: u32 = 5_000;
133130
let mut sleep_time = None;
@@ -163,14 +160,11 @@ pub async fn expired_message_cleaner_loop(pool: &DatabaseConnection) -> Result<(
163160
tracing::debug!(elapsed =? start.elapsed(), "expired {} payloads", rows_affected);
164161
}
165162

166-
sleep_time = match rows_affected {
167-
0 => Some(IDLE),
168-
count if count <= SLOWING_THRESHOLD => {
169-
tracing::trace!("slowing down...");
170-
Some(SLOWING)
171-
}
172-
// Any non-zero count above the slowing threshold gets no sleep.
173-
_ => None,
163+
sleep_time = if rows_affected < (BATCH_SIZE as _) {
164+
Some(IDLE)
165+
} else {
166+
// When we see full batches, don't sleep at all.
167+
None
174168
};
175169
}
176170
}

0 commit comments

Comments
 (0)