improvement: reduce logging, especially for database pool size

This commit is contained in:
Greg Heartsfield 2022-12-22 15:47:33 -06:00
parent 8ea732cbe5
commit b80b54cd9d
2 changed files with 13 additions and 7 deletions

View File

@ -5,7 +5,7 @@ use crate::error::Result;
use crate::subscription::Subscription; use crate::subscription::Subscription;
use std::collections::HashMap; use std::collections::HashMap;
use tracing::{debug, info}; use tracing::{debug, trace};
use uuid::Uuid; use uuid::Uuid;
/// A subscription identifier has a maximum length /// A subscription identifier has a maximum length
@ -74,7 +74,7 @@ impl ClientConn {
// prevent arbitrarily long subscription identifiers from // prevent arbitrarily long subscription identifiers from
// being used. // being used.
if sub_id_len > MAX_SUBSCRIPTION_ID_LEN { if sub_id_len > MAX_SUBSCRIPTION_ID_LEN {
info!( debug!(
"ignoring sub request with excessive length: ({})", "ignoring sub request with excessive length: ({})",
sub_id_len sub_id_len
); );
@ -84,7 +84,7 @@ impl ClientConn {
if self.subscriptions.contains_key(&k) { if self.subscriptions.contains_key(&k) {
self.subscriptions.remove(&k); self.subscriptions.remove(&k);
self.subscriptions.insert(k, s.clone()); self.subscriptions.insert(k, s.clone());
debug!( trace!(
"replaced existing subscription (cid: {}, sub: {:?})", "replaced existing subscription (cid: {}, sub: {:?})",
self.get_client_prefix(), self.get_client_prefix(),
s.get_id() s.get_id()
@ -98,7 +98,7 @@ impl ClientConn {
} }
// add subscription // add subscription
self.subscriptions.insert(k, s); self.subscriptions.insert(k, s);
debug!( trace!(
"registered new subscription, currently have {} active subs (cid: {})", "registered new subscription, currently have {} active subs (cid: {})",
self.subscriptions.len(), self.subscriptions.len(),
self.get_client_prefix(), self.get_client_prefix(),
@ -110,7 +110,7 @@ impl ClientConn {
pub fn unsubscribe(&mut self, c: &Close) { pub fn unsubscribe(&mut self, c: &Close) {
// TODO: return notice if subscription did not exist. // TODO: return notice if subscription did not exist.
self.subscriptions.remove(&c.id); self.subscriptions.remove(&c.id);
debug!( trace!(
"removed subscription, currently have {} active subs (cid: {})", "removed subscription, currently have {} active subs (cid: {})",
self.subscriptions.len(), self.subscriptions.len(),
self.get_client_prefix(), self.get_client_prefix(),

View File

@ -667,13 +667,19 @@ fn _pool_at_capacity(pool: &SqlitePool) -> bool {
state.idle_connections == 0 state.idle_connections == 0
} }
/// Log pool stats
fn log_pool_stats(name: &str, pool: &SqlitePool) { fn log_pool_stats(name: &str, pool: &SqlitePool) {
let state: r2d2::State = pool.state(); let state: r2d2::State = pool.state();
let in_use_cxns = state.connections - state.idle_connections; let in_use_cxns = state.connections - state.idle_connections;
debug!( trace!(
"DB pool {:?} usage (in_use: {}, available: {})", "DB pool {:?} usage (in_use: {}, available: {})",
name, in_use_cxns, state.connections name,
in_use_cxns,
state.connections
); );
if state.connections == in_use_cxns {
debug!("DB pool {:?} is empty (in_use: {})", name, in_use_cxns);
}
} }
/// Perform database maintenance on a regular basis /// Perform database maintenance on a regular basis