commit 4e51e61d16c76e932e0de2b40df420284021bac8
parent 5c8390bbe0bf98e13ce43c6719e9c9cc9a42a42a
Author: Greg Heartsfield <scsibug@imap.cc>
Date: Wed, 5 Jan 2022 18:30:47 -0500
improvement: display rate limit messages max once per sec
Diffstat:
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/db.rs b/src/db.rs
@@ -136,6 +136,7 @@ pub async fn db_writer(
upgrade_db(&mut conn)?;
// get rate limit settings
let rps_setting = config.limits.messages_per_sec;
+ let mut most_recent_rate_limit = Instant::now();
let mut lim_opt = None;
let clock = governor::clock::QuantaClock::default();
if let Some(rps) = rps_setting {
@@ -182,8 +183,20 @@ pub async fn db_writer(
if event_write {
if let Some(ref lim) = lim_opt {
if let Err(n) = lim.check() {
- info!("Rate limiting event creation");
- thread::sleep(n.wait_time_from(clock.now()));
+ let wait_for = n.wait_time_from(clock.now());
+ // check if we have recently logged rate
+ // limits, but print out a message only once
+ // per second.
+ if most_recent_rate_limit.elapsed().as_secs() > 1 {
+ warn!(
+ "rate limit reached for event creation (sleep for {:?})",
+ wait_for
+ );
+ // reset last rate limit message
+ most_recent_rate_limit = Instant::now();
+ }
+ // block event writes, allowing them to queue up
+ thread::sleep(wait_for);
continue;
}
}