From c9a2a4738856b3792deae1215e3821e8da857464 Mon Sep 17 00:00:00 2001 From: Mingwei Zhang Date: Fri, 2 Jun 2023 15:49:13 -0700 Subject: [PATCH 1/2] insert actual NULL instead of empty strings --- src/msg_store.rs | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/msg_store.rs b/src/msg_store.rs index 6f94516..58480c2 100644 --- a/src/msg_store.rs +++ b/src/msg_store.rs @@ -6,9 +6,9 @@ use itertools::Itertools; macro_rules! option_to_string { ($a:expr) => { if let Some(v) = $a { - v.to_string() + format!("'{}'", v) } else { - String::new() + "NULL".to_string() } }; } @@ -58,9 +58,9 @@ impl MsgStore { #[inline(always)] fn option_to_string_communities(o: &Option>) -> String { if let Some(v) = o { - v.iter().join(" ") + format!("'{}'", v.iter().join(" ")) } else { - String::new() + "NULL".to_string() } } @@ -77,23 +77,23 @@ impl MsgStore { }; let origin_string = elem.origin_asns.as_ref().map(|asns| asns.get(0).unwrap()); format!( - "('{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}','{}')", - elem.timestamp as u32, - t, - elem.peer_ip, - elem.peer_asn, - elem.prefix, - option_to_string!(&elem.next_hop), - option_to_string!(&elem.as_path), - option_to_string!(origin_string), - option_to_string!(&elem.origin), - option_to_string!(&elem.local_pref), - option_to_string!(&elem.med), - Self::option_to_string_communities(&elem.communities), - option_to_string!(&elem.atomic), - option_to_string!(&elem.aggr_asn), - option_to_string!(&elem.aggr_ip), - ) + "('{}','{}','{}','{}','{}', {},{},{},{},{},{},{},{},{},{})", + elem.timestamp as u32, + t, + elem.peer_ip, + elem.peer_asn, + elem.prefix, + option_to_string!(&elem.next_hop), + option_to_string!(&elem.as_path), + option_to_string!(origin_string), + option_to_string!(&elem.origin), + option_to_string!(&elem.local_pref), + option_to_string!(&elem.med), + Self::option_to_string_communities(&elem.communities), + option_to_string!(&elem.atomic), + option_to_string!(&elem.aggr_asn), + option_to_string!(&elem.aggr_ip), + ) }) .join(", ") .to_string(); From 3350c709d579d3d70d6d8120239a59734347df68 Mon Sep 17 00:00:00 2001 From: Mingwei Zhang Date: Fri, 2 Jun 2023 16:02:34 -0700 Subject: [PATCH 2/2] increase msg batch insert size --- src/monocle.rs | 2 +- src/msg_store.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/monocle.rs b/src/monocle.rs index 802df96..98f7a4f 100644 --- a/src/monocle.rs +++ b/src/monocle.rs @@ -491,7 +491,7 @@ fn main() { for elem in receiver { msg_count += 1; msg_cache.push(elem); - if msg_cache.len() >= 500 { + if msg_cache.len() >= 100000 { db.insert_elems(&msg_cache); msg_cache.clear(); } diff --git a/src/msg_store.rs b/src/msg_store.rs index 58480c2..d8f914e 100644 --- a/src/msg_store.rs +++ b/src/msg_store.rs @@ -65,7 +65,7 @@ impl MsgStore { } pub fn insert_elems(&self, elems: &[BgpElem]) { - for elems in elems.chunks(100) { + for elems in elems.chunks(10000) { let values = elems .iter() .map(|elem| {