stats_accounting

This commit is contained in:
John Smith
2022-03-19 18:19:40 -04:00
parent babe176747
commit 3888a832a0
19 changed files with 285 additions and 67 deletions

View File

@@ -32,7 +32,8 @@ pub struct BucketEntry {
min_max_version: Option<(u8, u8)>,
last_connection: Option<(ConnectionDescriptor, u64)>,
dial_infos: Vec<DialInfo>,
stats_accounting: StatsAccounting,
latency_stats_accounting: LatencyStatsAccounting,
transfer_stats_accounting: TransferStatsAccounting,
peer_stats: PeerStats,
}
@@ -44,7 +45,8 @@ impl BucketEntry {
min_max_version: None,
last_connection: None,
dial_infos: Vec::new(),
stats_accounting: StatsAccounting::new(),
latency_stats_accounting: LatencyStatsAccounting::new(),
transfer_stats_accounting: TransferStatsAccounting::new(),
peer_stats: PeerStats {
time_added: now,
last_seen: None,
@@ -133,13 +135,16 @@ impl BucketEntry {
///// stats methods
// called every ROLLING_TRANSFERS_INTERVAL_SECS seconds
pub(super) fn roll_transfers(&mut self, last_ts: u64, cur_ts: u64) {
self.stats_accounting
.roll_transfers(last_ts, cur_ts, &mut self.peer_stats.transfer);
self.transfer_stats_accounting.roll_transfers(
last_ts,
cur_ts,
&mut self.peer_stats.transfer,
);
}
// Called for every round trip packet we receive
fn record_latency(&mut self, latency: u64) {
self.peer_stats.latency = Some(self.stats_accounting.record_latency(latency));
self.peer_stats.latency = Some(self.latency_stats_accounting.record_latency(latency));
}
///// state machine handling
@@ -255,7 +260,7 @@ impl BucketEntry {
pub(super) fn ping_sent(&mut self, ts: u64, bytes: u64) {
self.peer_stats.ping_stats.total_sent += 1;
self.stats_accounting.add_up(bytes);
self.transfer_stats_accounting.add_up(bytes);
self.peer_stats.ping_stats.in_flight += 1;
self.peer_stats.ping_stats.last_pinged = Some(ts);
// if we haven't heard from this node yet and it's our first attempt at contacting it
@@ -265,14 +270,14 @@ impl BucketEntry {
}
}
pub(super) fn ping_rcvd(&mut self, ts: u64, bytes: u64) {
self.stats_accounting.add_down(bytes);
self.transfer_stats_accounting.add_down(bytes);
self.touch_last_seen(ts);
}
pub(super) fn pong_sent(&mut self, _ts: u64, bytes: u64) {
self.stats_accounting.add_up(bytes);
self.transfer_stats_accounting.add_up(bytes);
}
pub(super) fn pong_rcvd(&mut self, send_ts: u64, recv_ts: u64, bytes: u64) {
self.stats_accounting.add_down(bytes);
self.transfer_stats_accounting.add_down(bytes);
self.peer_stats.ping_stats.in_flight -= 1;
self.peer_stats.ping_stats.total_returned += 1;
self.peer_stats.ping_stats.consecutive_pongs += 1;
@@ -294,7 +299,7 @@ impl BucketEntry {
self.peer_stats.ping_stats.first_consecutive_pong_time = None;
}
pub(super) fn question_sent(&mut self, ts: u64, bytes: u64) {
self.stats_accounting.add_up(bytes);
self.transfer_stats_accounting.add_up(bytes);
// if we haven't heard from this node yet and it's our first attempt at contacting it
// then we set the last_seen time
if self.peer_stats.last_seen.is_none() {
@@ -302,14 +307,14 @@ impl BucketEntry {
}
}
pub(super) fn question_rcvd(&mut self, ts: u64, bytes: u64) {
self.stats_accounting.add_down(bytes);
self.transfer_stats_accounting.add_down(bytes);
self.touch_last_seen(ts);
}
pub(super) fn answer_sent(&mut self, _ts: u64, bytes: u64) {
self.stats_accounting.add_up(bytes);
self.transfer_stats_accounting.add_up(bytes);
}
pub(super) fn answer_rcvd(&mut self, send_ts: u64, recv_ts: u64, bytes: u64) {
self.stats_accounting.add_down(bytes);
self.transfer_stats_accounting.add_down(bytes);
self.record_latency(recv_ts - send_ts);
self.touch_last_seen(recv_ts);
}

View File

@@ -7,8 +7,14 @@ impl RoutingTable {
out += "Routing Table Info:\n";
out += &format!(" Node Id: {}\n", inner.node_id.encode());
out += &format!(" Stats Accounting: {:#?}\n\n", inner.stats_accounting);
out += &format!(" Transfer Stats: {:#?}\n\n", inner.transfer_stats);
out += &format!(
" Self Transfer Stats Accounting: {:#?}\n\n",
inner.self_transfer_stats_accounting
);
out += &format!(
" Self Transfer Stats: {:#?}\n\n",
inner.self_transfer_stats
);
out
}

View File

@@ -50,12 +50,14 @@ struct RoutingTableInner {
buckets: Vec<Bucket>,
dial_info_details: Vec<DialInfoDetail>,
bucket_entry_count: usize,
// Waiters
eventual_changed_dial_info: Eventual,
// Transfer stats for this node
stats_accounting: StatsAccounting,
// latency: Option<LatencyStats>,
transfer_stats: TransferStatsDownUp,
self_latency_stats_accounting: LatencyStatsAccounting,
self_transfer_stats_accounting: TransferStatsAccounting,
self_transfer_stats: TransferStatsDownUp,
}
struct RoutingTableUnlockedInner {
@@ -83,8 +85,9 @@ impl RoutingTable {
dial_info_details: Vec::new(),
bucket_entry_count: 0,
eventual_changed_dial_info: Eventual::new(),
stats_accounting: StatsAccounting::new(),
transfer_stats: TransferStatsDownUp::default(),
self_latency_stats_accounting: LatencyStatsAccounting::new(),
self_transfer_stats_accounting: TransferStatsAccounting::new(),
self_transfer_stats: TransferStatsDownUp::default(),
}
}
fn new_unlocked_inner(config: VeilidConfig) -> RoutingTableUnlockedInner {
@@ -609,9 +612,11 @@ impl RoutingTable {
let inner = &mut *self.inner.lock();
// Roll our own node's transfers
inner
.stats_accounting
.roll_transfers(last_ts, cur_ts, &mut inner.transfer_stats);
inner.self_transfer_stats_accounting.roll_transfers(
last_ts,
cur_ts,
&mut inner.self_transfer_stats,
);
// Roll all bucket entry transfers
for b in &mut inner.buckets {
@@ -649,25 +654,37 @@ impl RoutingTable {
// Stats Accounting
pub fn ping_sent(&self, node_ref: NodeRef, ts: u64, bytes: u64) {
self.inner.lock().stats_accounting.add_up(bytes);
self.inner
.lock()
.self_transfer_stats_accounting
.add_up(bytes);
node_ref.operate(|e| {
e.ping_sent(ts, bytes);
})
}
pub fn ping_rcvd(&self, node_ref: NodeRef, ts: u64, bytes: u64) {
self.inner.lock().stats_accounting.add_down(bytes);
self.inner
.lock()
.self_transfer_stats_accounting
.add_down(bytes);
node_ref.operate(|e| {
e.ping_rcvd(ts, bytes);
})
}
pub fn pong_sent(&self, node_ref: NodeRef, ts: u64, bytes: u64) {
self.inner.lock().stats_accounting.add_up(bytes);
self.inner
.lock()
.self_transfer_stats_accounting
.add_up(bytes);
node_ref.operate(|e| {
e.pong_sent(ts, bytes);
})
}
pub fn pong_rcvd(&self, node_ref: NodeRef, send_ts: u64, recv_ts: u64, bytes: u64) {
self.inner.lock().stats_accounting.add_down(bytes);
self.inner
.lock()
.self_transfer_stats_accounting
.add_down(bytes);
node_ref.operate(|e| {
e.pong_rcvd(send_ts, recv_ts, bytes);
})
@@ -678,25 +695,37 @@ impl RoutingTable {
})
}
pub fn question_sent(&self, node_ref: NodeRef, ts: u64, bytes: u64) {
self.inner.lock().stats_accounting.add_up(bytes);
self.inner
.lock()
.self_transfer_stats_accounting
.add_up(bytes);
node_ref.operate(|e| {
e.question_sent(ts, bytes);
})
}
pub fn question_rcvd(&self, node_ref: NodeRef, ts: u64, bytes: u64) {
self.inner.lock().stats_accounting.add_down(bytes);
self.inner
.lock()
.self_transfer_stats_accounting
.add_down(bytes);
node_ref.operate(|e| {
e.question_rcvd(ts, bytes);
})
}
pub fn answer_sent(&self, node_ref: NodeRef, ts: u64, bytes: u64) {
self.inner.lock().stats_accounting.add_up(bytes);
self.inner
.lock()
.self_transfer_stats_accounting
.add_up(bytes);
node_ref.operate(|e| {
e.answer_sent(ts, bytes);
})
}
pub fn answer_rcvd(&self, node_ref: NodeRef, send_ts: u64, recv_ts: u64, bytes: u64) {
self.inner.lock().stats_accounting.add_down(bytes);
self.inner
.lock()
.self_transfer_stats_accounting
.add_down(bytes);
node_ref.operate(|e| {
e.answer_rcvd(send_ts, recv_ts, bytes);
})

View File

@@ -19,16 +19,14 @@ pub struct TransferCount {
}
#[derive(Debug, Clone, Default)]
pub struct StatsAccounting {
rolling_latencies: VecDeque<u64>,
pub struct TransferStatsAccounting {
rolling_transfers: VecDeque<TransferCount>,
current_transfer: TransferCount,
}
impl StatsAccounting {
impl TransferStatsAccounting {
pub fn new() -> Self {
Self {
rolling_latencies: VecDeque::new(),
rolling_transfers: VecDeque::new(),
current_transfer: TransferCount::default(),
}
@@ -79,6 +77,19 @@ impl StatsAccounting {
transfer_stats.down.average /= len;
transfer_stats.up.average /= len;
}
}
#[derive(Debug, Clone, Default)]
pub struct LatencyStatsAccounting {
rolling_latencies: VecDeque<u64>,
}
impl LatencyStatsAccounting {
pub fn new() -> Self {
Self {
rolling_latencies: VecDeque::new(),
}
}
pub fn record_latency(&mut self, latency: u64) -> veilid_api::LatencyStats {
while self.rolling_latencies.len() >= ROLLING_LATENCIES_SIZE {