mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-23 01:16:30 +00:00
Calculate averages correctly and preserve totals like before (#429)
* Reset totals after avg calculation * like it used to be
This commit is contained in:
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -250,6 +250,12 @@ dependencies = [
|
|||||||
"subtle",
|
"subtle",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "either"
|
||||||
|
version = "1.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "enum-as-inner"
|
name = "enum-as-inner"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
@@ -658,6 +664,15 @@ dependencies = [
|
|||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itertools"
|
||||||
|
version = "0.10.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473"
|
||||||
|
dependencies = [
|
||||||
|
"either",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.5"
|
version = "1.0.5"
|
||||||
@@ -897,6 +912,7 @@ dependencies = [
|
|||||||
"futures",
|
"futures",
|
||||||
"hmac",
|
"hmac",
|
||||||
"hyper",
|
"hyper",
|
||||||
|
"itertools",
|
||||||
"jemallocator",
|
"jemallocator",
|
||||||
"log",
|
"log",
|
||||||
"md-5",
|
"md-5",
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ rustls = { version = "0.21", features = ["dangerous_configuration"] }
|
|||||||
trust-dns-resolver = "0.22.0"
|
trust-dns-resolver = "0.22.0"
|
||||||
tokio-test = "0.4.2"
|
tokio-test = "0.4.2"
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
|
itertools = "0.10"
|
||||||
|
|
||||||
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
||||||
jemallocator = "0.5.0"
|
jemallocator = "0.5.0"
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use log::warn;
|
|
||||||
use std::sync::atomic::*;
|
use std::sync::atomic::*;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -13,6 +12,16 @@ pub struct AddressStats {
|
|||||||
pub total_query_time: Arc<AtomicU64>,
|
pub total_query_time: Arc<AtomicU64>,
|
||||||
pub total_wait_time: Arc<AtomicU64>,
|
pub total_wait_time: Arc<AtomicU64>,
|
||||||
pub total_errors: Arc<AtomicU64>,
|
pub total_errors: Arc<AtomicU64>,
|
||||||
|
|
||||||
|
pub old_total_xact_count: Arc<AtomicU64>,
|
||||||
|
pub old_total_query_count: Arc<AtomicU64>,
|
||||||
|
pub old_total_received: Arc<AtomicU64>,
|
||||||
|
pub old_total_sent: Arc<AtomicU64>,
|
||||||
|
pub old_total_xact_time: Arc<AtomicU64>,
|
||||||
|
pub old_total_query_time: Arc<AtomicU64>,
|
||||||
|
pub old_total_wait_time: Arc<AtomicU64>,
|
||||||
|
pub old_total_errors: Arc<AtomicU64>,
|
||||||
|
|
||||||
pub avg_query_count: Arc<AtomicU64>,
|
pub avg_query_count: Arc<AtomicU64>,
|
||||||
pub avg_query_time: Arc<AtomicU64>,
|
pub avg_query_time: Arc<AtomicU64>,
|
||||||
pub avg_recv: Arc<AtomicU64>,
|
pub avg_recv: Arc<AtomicU64>,
|
||||||
@@ -104,16 +113,16 @@ impl AddressStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_averages(&self) {
|
pub fn update_averages(&self) {
|
||||||
let (totals, averages) = self.fields_iterators();
|
let (totals, averages, old_totals) = self.fields_iterators();
|
||||||
for data in totals.iter().zip(averages.iter()) {
|
for data in itertools::izip!(totals, averages, old_totals) {
|
||||||
let (total, average) = data;
|
let (total, average, old_total) = data;
|
||||||
if let Err(err) = average.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |avg| {
|
let total = total.load(Ordering::Relaxed);
|
||||||
let total = total.load(Ordering::Relaxed);
|
let old = old_total.load(Ordering::Relaxed);
|
||||||
let avg = (total - avg) / (crate::stats::STAT_PERIOD / 1_000); // Avg / second
|
average.store(
|
||||||
Some(avg)
|
(total - old) / (crate::stats::STAT_PERIOD / 1_000),
|
||||||
}) {
|
Ordering::Relaxed,
|
||||||
warn!("Could not update averages for addresses stats, {:?}", err);
|
); // Avg / second
|
||||||
}
|
old_total.store(total, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,27 +132,42 @@ impl AddressStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fields_iterators(&self) -> (Vec<Arc<AtomicU64>>, Vec<Arc<AtomicU64>>) {
|
fn fields_iterators(
|
||||||
|
&self,
|
||||||
|
) -> (
|
||||||
|
Vec<Arc<AtomicU64>>,
|
||||||
|
Vec<Arc<AtomicU64>>,
|
||||||
|
Vec<Arc<AtomicU64>>,
|
||||||
|
) {
|
||||||
let mut totals: Vec<Arc<AtomicU64>> = Vec::new();
|
let mut totals: Vec<Arc<AtomicU64>> = Vec::new();
|
||||||
let mut averages: Vec<Arc<AtomicU64>> = Vec::new();
|
let mut averages: Vec<Arc<AtomicU64>> = Vec::new();
|
||||||
|
let mut old_totals: Vec<Arc<AtomicU64>> = Vec::new();
|
||||||
|
|
||||||
totals.push(self.total_xact_count.clone());
|
totals.push(self.total_xact_count.clone());
|
||||||
|
old_totals.push(self.old_total_xact_count.clone());
|
||||||
averages.push(self.avg_xact_count.clone());
|
averages.push(self.avg_xact_count.clone());
|
||||||
totals.push(self.total_query_count.clone());
|
totals.push(self.total_query_count.clone());
|
||||||
|
old_totals.push(self.old_total_query_count.clone());
|
||||||
averages.push(self.avg_query_count.clone());
|
averages.push(self.avg_query_count.clone());
|
||||||
totals.push(self.total_received.clone());
|
totals.push(self.total_received.clone());
|
||||||
|
old_totals.push(self.old_total_received.clone());
|
||||||
averages.push(self.avg_recv.clone());
|
averages.push(self.avg_recv.clone());
|
||||||
totals.push(self.total_sent.clone());
|
totals.push(self.total_sent.clone());
|
||||||
|
old_totals.push(self.old_total_sent.clone());
|
||||||
averages.push(self.avg_sent.clone());
|
averages.push(self.avg_sent.clone());
|
||||||
totals.push(self.total_xact_time.clone());
|
totals.push(self.total_xact_time.clone());
|
||||||
|
old_totals.push(self.old_total_xact_time.clone());
|
||||||
averages.push(self.avg_xact_time.clone());
|
averages.push(self.avg_xact_time.clone());
|
||||||
totals.push(self.total_query_time.clone());
|
totals.push(self.total_query_time.clone());
|
||||||
|
old_totals.push(self.old_total_query_time.clone());
|
||||||
averages.push(self.avg_query_time.clone());
|
averages.push(self.avg_query_time.clone());
|
||||||
totals.push(self.total_wait_time.clone());
|
totals.push(self.total_wait_time.clone());
|
||||||
|
old_totals.push(self.old_total_wait_time.clone());
|
||||||
averages.push(self.avg_wait_time.clone());
|
averages.push(self.avg_wait_time.clone());
|
||||||
totals.push(self.total_errors.clone());
|
totals.push(self.total_errors.clone());
|
||||||
|
old_totals.push(self.old_total_errors.clone());
|
||||||
averages.push(self.avg_errors.clone());
|
averages.push(self.avg_errors.clone());
|
||||||
|
|
||||||
(totals, averages)
|
(totals, averages, old_totals)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user