Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix: make drainer sleep on every loop interval instead of cycle end (#2951)

Kartikeya Hegdee8df69092f4c
diff --git a/crates/drainer/src/lib.rs b/crates/drainer/src/lib.rs
index 04dff49b74..94a29e3b0a 100644
--- a/crates/drainer/src/lib.rs
+++ b/crates/drainer/src/lib.rs
@@ -67,9 +67,9 @@ pub async fn start_drainer(
stream_index = utils::increment_stream_index(
(stream_index, jobs_picked.clone()),
number_of_streams,
- &mut loop_interval,
)
.await;
+ loop_interval.tick().await;
}
Ok(()) | Err(mpsc::error::TryRecvError::Disconnected) => {
logger::info!("Awaiting shutdown!");
@@ -114,6 +114,7 @@ pub async fn redis_error_receiver(rx: oneshot::Receiver<()>, shutdown_channel: m
}
}
+#[router_env::instrument(skip_all)]
async fn drainer_handler(
store: Arc<Store>,
stream_index: u8,
diff --git a/crates/drainer/src/settings.rs b/crates/drainer/src/settings.rs
index cc64a99e46..8101abf502 100644
--- a/crates/drainer/src/settings.rs
+++ b/crates/drainer/src/settings.rs
@@ -79,7 +79,7 @@ impl Default for DrainerSettings {
num_partitions: 64,
max_read_count: 100,
shutdown_interval: 1000, // in milliseconds
- loop_interval: 500, // in milliseconds
+ loop_interval: 100, // in milliseconds
}
}
}
diff --git a/crates/drainer/src/utils.rs b/crates/drainer/src/utils.rs
index 5abc7e474c..2bd9f092f1 100644
--- a/crates/drainer/src/utils.rs
+++ b/crates/drainer/src/utils.rs
@@ -8,12 +8,13 @@ use redis_interface as redis;
use crate::{
errors::{self, DrainerError},
- logger, metrics, services,
+ logger, metrics, services, tracing,
};
pub type StreamEntries = Vec<(String, HashMap<String, String>)>;
pub type StreamReadResult = HashMap<String, StreamEntries>;
+#[router_env::instrument(skip_all)]
pub async fn is_stream_available(stream_index: u8, store: Arc<services::Store>) -> bool {
let stream_key_flag = get_stream_key_flag(store.clone(), stream_index);
@@ -132,10 +133,8 @@ pub fn parse_stream_entries<'a>(
pub async fn increment_stream_index(
(index, jobs_picked): (u8, Arc<atomic::AtomicU8>),
total_streams: u8,
- interval: &mut tokio::time::Interval,
) -> u8 {
if index == total_streams - 1 {
- interval.tick().await;
match jobs_picked.load(atomic::Ordering::SeqCst) {
0 => metrics::CYCLES_COMPLETED_UNSUCCESSFULLY.add(&metrics::CONTEXT, 1, &[]),
_ => metrics::CYCLES_COMPLETED_SUCCESSFULLY.add(&metrics::CONTEXT, 1, &[]),
diff --git a/crates/router/src/configs/defaults.rs b/crates/router/src/configs/defaults.rs
index 2320eabacd..2eddaf3084 100644
--- a/crates/router/src/configs/defaults.rs
+++ b/crates/router/src/configs/defaults.rs
@@ -99,7 +99,7 @@ impl Default for super::settings::DrainerSettings {
num_partitions: 64,
max_read_count: 100,
shutdown_interval: 1000,
- loop_interval: 500,
+ loop_interval: 100,
}
}
}