bank: Add executors cache metrics
This commit is contained in:
committed by
Trent Nelson
parent
5771c36d3f
commit
6d76db1de5
@ -242,6 +242,53 @@ pub struct SquashTiming {
|
|||||||
|
|
||||||
type EpochCount = u64;
|
type EpochCount = u64;
|
||||||
|
|
||||||
|
mod executor_cache {
|
||||||
|
use super::*;
|
||||||
|
use log;
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct Stats {
|
||||||
|
pub hits: u64,
|
||||||
|
pub misses: u64,
|
||||||
|
pub evictions: HashMap<Pubkey, u64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Stats {
|
||||||
|
pub fn submit(&self, slot: Slot) {
|
||||||
|
let evictions: u64 = self.evictions.values().sum();
|
||||||
|
datapoint_info!(
|
||||||
|
"bank-executor-cache-stats",
|
||||||
|
("slot", slot, i64),
|
||||||
|
("hits", self.hits, i64),
|
||||||
|
("misses", self.misses, i64),
|
||||||
|
("evictions", evictions, i64),
|
||||||
|
);
|
||||||
|
debug!(
|
||||||
|
"Executor Cache Stats -- Hits: {}, Misses: {}, Evictions: {}",
|
||||||
|
self.hits, self.misses, evictions
|
||||||
|
);
|
||||||
|
if log_enabled!(log::Level::Trace) && !self.evictions.is_empty() {
|
||||||
|
let mut evictions = self.evictions.iter().collect::<Vec<_>>();
|
||||||
|
evictions.sort_by_key(|e| e.1);
|
||||||
|
let evictions = evictions
|
||||||
|
.into_iter()
|
||||||
|
.rev()
|
||||||
|
.map(|(program_id, evictions)| {
|
||||||
|
format!(" {:<44} {}", program_id.to_string(), evictions)
|
||||||
|
})
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let evictions = evictions.join("\n");
|
||||||
|
trace!(
|
||||||
|
"Eviction Details:\n {:<44} {}\n{}",
|
||||||
|
"Program",
|
||||||
|
"Count",
|
||||||
|
evictions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const MAX_CACHED_EXECUTORS: usize = 100; // 10 MB assuming programs are around 100k
|
const MAX_CACHED_EXECUTORS: usize = 100; // 10 MB assuming programs are around 100k
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct CachedExecutorsEntry {
|
struct CachedExecutorsEntry {
|
||||||
@ -255,6 +302,7 @@ struct CachedExecutors {
|
|||||||
max: usize,
|
max: usize,
|
||||||
current_epoch: Epoch,
|
current_epoch: Epoch,
|
||||||
executors: HashMap<Pubkey, CachedExecutorsEntry>,
|
executors: HashMap<Pubkey, CachedExecutorsEntry>,
|
||||||
|
stats: executor_cache::Stats,
|
||||||
}
|
}
|
||||||
impl Default for CachedExecutors {
|
impl Default for CachedExecutors {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@ -262,6 +310,7 @@ impl Default for CachedExecutors {
|
|||||||
max: MAX_CACHED_EXECUTORS,
|
max: MAX_CACHED_EXECUTORS,
|
||||||
current_epoch: Epoch::default(),
|
current_epoch: Epoch::default(),
|
||||||
executors: HashMap::default(),
|
executors: HashMap::default(),
|
||||||
|
stats: executor_cache::Stats::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -290,6 +339,7 @@ impl Clone for CachedExecutors {
|
|||||||
max: self.max,
|
max: self.max,
|
||||||
current_epoch: self.current_epoch,
|
current_epoch: self.current_epoch,
|
||||||
executors: executors.collect(),
|
executors: executors.collect(),
|
||||||
|
stats: executor_cache::Stats::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,6 +363,7 @@ impl CachedExecutors {
|
|||||||
max: self.max,
|
max: self.max,
|
||||||
current_epoch: epoch,
|
current_epoch: epoch,
|
||||||
executors: executors.collect(),
|
executors: executors.collect(),
|
||||||
|
stats: executor_cache::Stats::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,6 +372,7 @@ impl CachedExecutors {
|
|||||||
max,
|
max,
|
||||||
current_epoch,
|
current_epoch,
|
||||||
executors: HashMap::new(),
|
executors: HashMap::new(),
|
||||||
|
stats: executor_cache::Stats::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,9 +385,11 @@ impl CachedExecutors {
|
|||||||
|
|
||||||
fn put(&mut self, pubkey: &Pubkey, executor: Arc<dyn Executor>) {
|
fn put(&mut self, pubkey: &Pubkey, executor: Arc<dyn Executor>) {
|
||||||
let entry = if let Some(mut entry) = self.executors.remove(pubkey) {
|
let entry = if let Some(mut entry) = self.executors.remove(pubkey) {
|
||||||
|
saturating_add_assign!(self.stats.hits, 1);
|
||||||
entry.executor = executor;
|
entry.executor = executor;
|
||||||
entry
|
entry
|
||||||
} else {
|
} else {
|
||||||
|
saturating_add_assign!(self.stats.misses, 1);
|
||||||
if self.executors.len() >= self.max {
|
if self.executors.len() >= self.max {
|
||||||
let mut least = u64::MAX;
|
let mut least = u64::MAX;
|
||||||
let default_key = Pubkey::default();
|
let default_key = Pubkey::default();
|
||||||
@ -350,6 +404,11 @@ impl CachedExecutors {
|
|||||||
}
|
}
|
||||||
let least_key = *least_key;
|
let least_key = *least_key;
|
||||||
let _ = self.executors.remove(&least_key);
|
let _ = self.executors.remove(&least_key);
|
||||||
|
self.stats
|
||||||
|
.evictions
|
||||||
|
.entry(least_key)
|
||||||
|
.and_modify(|c| saturating_add_assign!(*c, 1))
|
||||||
|
.or_insert(1);
|
||||||
}
|
}
|
||||||
CachedExecutorsEntry {
|
CachedExecutorsEntry {
|
||||||
prev_epoch_count: 0,
|
prev_epoch_count: 0,
|
||||||
@ -1507,6 +1566,13 @@ impl Bank {
|
|||||||
("time_us", time.as_us(), i64),
|
("time_us", time.as_us(), i64),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
parent
|
||||||
|
.cached_executors
|
||||||
|
.read()
|
||||||
|
.unwrap()
|
||||||
|
.stats
|
||||||
|
.submit(parent.slot());
|
||||||
|
|
||||||
new
|
new
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user