From 1fa3341d68728fe38ffc12aeda579ab923b409ae Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 29 May 2020 09:16:13 +0200 Subject: [PATCH] rrd: reduce io by saving data only once a minute --- src/rrd/cache.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rrd/cache.rs b/src/rrd/cache.rs index a89d0615..33e99935 100644 --- a/src/rrd/cache.rs +++ b/src/rrd/cache.rs @@ -40,7 +40,7 @@ fn now() -> Result { Ok(time.as_secs_f64()) } -pub fn update_value(rel_path: &str, value: f64, dst: DST) -> Result<(), Error> { +pub fn update_value(rel_path: &str, value: f64, dst: DST, save: bool) -> Result<(), Error> { let mut path = PathBuf::from(PBS_RRD_BASEDIR); path.push(rel_path); @@ -52,7 +52,7 @@ pub fn update_value(rel_path: &str, value: f64, dst: DST) -> Result<(), Error> { if let Some(rrd) = map.get_mut(rel_path) { rrd.update(now, value); - rrd.save(&path)?; + if save { rrd.save(&path)?; } } else { let mut rrd = match RRD::load(&path) { Ok(rrd) => rrd, @@ -64,7 +64,7 @@ pub fn update_value(rel_path: &str, value: f64, dst: DST) -> Result<(), Error> { }, }; rrd.update(now, value); - rrd.save(&path)?; + if save { rrd.save(&path)?; } map.insert(rel_path.into(), rrd); }