1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#[derive(Debug, Default, Clone)]
pub struct ShardStats {
pub executions_complete: u64,
pub executions_coalesced: u64,
pub executions_pending: usize,
pub keys_lru_evicted: u64,
pub keys_ttl_evicted: u64,
pub keys_taken: u64,
pub loads_in_progress: usize,
pub loads_failed: u64,
pub loads_not_found: u64,
pub loads_complete: u64,
pub data_size: usize,
pub expiring_keys: usize,
pub expiration_probes_ran: u64,
pub expiration_probes_expedited: u64,
}
impl ShardStats {
#[inline]
pub(super) fn record_pending_executions_completed(
&mut self,
pending_executions_completed: usize,
) {
self.executions_pending -= pending_executions_completed;
self.executions_complete += pending_executions_completed as u64;
if pending_executions_completed > 1 {
self.executions_coalesced += (pending_executions_completed - 1) as u64;
}
}
#[inline]
pub(super) fn record_load_complete(&mut self, result: Result<(), &crate::ShardError>) {
self.loads_in_progress -= 1;
match result {
Ok(()) => {
self.loads_complete += 1;
}
Err(crate::ShardError::UpstreamError { error }) => {
if error.is_not_found() {
self.loads_not_found += 1;
} else {
self.loads_failed += 1;
}
}
Err(_err) => {
self.loads_failed += 1;
}
}
}
pub fn merge_stats<S: IntoIterator<Item = ShardStats>>(stats: S) -> Self {
stats
.into_iter()
.fold(ShardStats::default(), |s, d| s.merge(d))
}
fn merge(self, other: ShardStats) -> Self {
Self {
executions_complete: self.executions_complete + other.executions_complete,
executions_coalesced: self.executions_coalesced + other.executions_coalesced,
executions_pending: self.executions_pending + other.executions_pending,
loads_in_progress: self.loads_in_progress + other.loads_in_progress,
data_size: self.data_size + other.data_size,
keys_lru_evicted: self.keys_lru_evicted + other.keys_lru_evicted,
keys_ttl_evicted: self.keys_ttl_evicted + other.keys_ttl_evicted,
keys_taken: self.keys_taken + other.keys_taken,
expiring_keys: self.expiring_keys + other.expiring_keys,
loads_failed: self.loads_failed + other.loads_failed,
loads_not_found: self.loads_not_found + other.loads_not_found,
loads_complete: self.loads_complete + other.loads_complete,
expiration_probes_ran: self.expiration_probes_ran + other.expiration_probes_ran,
expiration_probes_expedited: self.expiration_probes_expedited
+ other.expiration_probes_expedited,
}
}
}