Skip to content

Commit d061905

Browse files
committed
Avoid duplicate log messages when no reqs are chosen from the queue
1 parent cbeb36f commit d061905

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

router/src/queue.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ pub(crate) struct Queue<B: BatchType> {
123123
/// Id of the next batch
124124
next_batch_id: u64,
125125

126+
// Keep track what was logged in the last call to try_next_batch
127+
// so as to avoid many repeating entries in the log
128+
last_logged: Option<(usize, usize)>,
129+
126130
/// Just a constant empty map to reuse
127131
empty_map: IntMap<u64, Entry>,
128132
}
@@ -138,6 +142,7 @@ impl<B: BatchType> Queue<B> {
138142
next_id: 0,
139143
next_batch_id: 1,
140144
batch_type: PhantomData,
145+
last_logged: None,
141146
empty_map: IntMap::default(),
142147
}
143148
}
@@ -215,12 +220,14 @@ impl<B: BatchType> Queue<B> {
215220
let buffer_size = self.buffer.len();
216221
if buffer_size < min_size {
217222
// Not enough requests waiting to reach min_size
223+
self.last_logged = None;
218224
return None
219225
}
220226

221227
let mut total_count = entries.len();
222228
if total_count + min_size > self.config.size_limit {
223229
// Not enough space to fit min_size within max batch size
230+
self.last_logged = None;
224231
return None
225232
}
226233

@@ -290,6 +297,7 @@ impl<B: BatchType> Queue<B> {
290297
if <B>::exceeds_weight(tree, config.weight_limit, output_len) {
291298
if chosen_indices.len() + buffer_size < min_size + index + 1 {
292299
// We don't have enough remaining to meet min_size
300+
self.last_logged = None;
293301
return None
294302
}
295303
// Remove our tuple from the set
@@ -337,12 +345,21 @@ impl<B: BatchType> Queue<B> {
337345
}
338346

339347
let chosen_count = chosen_indices.len();
340-
info!("Chose {chosen_count} out of {buffer_size} requests from buffer, \
341-
total now {total_count}");
342348
if chosen_count == 0 {
349+
// Don't repeatedly log when no requests were chosen if the current/waiting
350+
// request counts haven't changed
351+
let current_counts = Some((buffer_size, total_count));
352+
if self.last_logged != current_counts {
353+
self.last_logged = current_counts;
354+
info!("Chose 0 out of {buffer_size} requests from buffer, total now {total_count}");
355+
}
343356
return None
344357
}
345358

359+
self.last_logged = None;
360+
info!("Chose {chosen_count} out of {buffer_size} requests from buffer, \
361+
total now {total_count}");
362+
346363
let some_now = Some(now);
347364
let requests = chosen_indices.iter().enumerate().map(|(i, index)| {
348365
let mut entry = self.buffer.remove(index - i).expect("bug");

0 commit comments

Comments
 (0)