Skip to content

Commit 9fea677

Browse files
committed
core, graph: Log more details about the entity cache
1 parent 2ce7566 commit 9fea677

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

core/src/subgraph/runner.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ where
215215
));
216216

217217
debug!(logger, "Start processing block";
218-
"triggers" => triggers.len(),
219-
"cached_entities" => self.state.entity_lfu_cache.len());
218+
"triggers" => triggers.len());
220219

221220
let proof_of_indexing = if self.inputs.store.supports_proof_of_indexing().await? {
222221
Some(Arc::new(AtomicRefCell::new(ProofOfIndexing::new(
@@ -400,12 +399,20 @@ where
400399
let ModificationsAndCache {
401400
modifications: mut mods,
402401
entity_lfu_cache: cache,
402+
evict_stats,
403403
} = block_state
404404
.entity_cache
405405
.as_modifications()
406406
.map_err(|e| BlockProcessingError::Unknown(e.into()))?;
407407
section.end();
408408

409+
debug!(self.logger, "Entity cache statistics";
410+
"weight" => evict_stats.new_weight,
411+
"evicted_weight" => evict_stats.evicted_weight,
412+
"count" => evict_stats.new_count,
413+
"evicted_count" => evict_stats.evicted_count,
414+
"stale_update" => evict_stats.stale_update);
415+
409416
// Check for offchain events and process them, including their entity modifications in the
410417
// set to be transacted.
411418
let offchain_events = self.ctx.offchain_monitor.ready_offchain_events()?;

graph/src/components/store/entity_cache.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::components::store::{self as s, Entity, EntityKey, EntityOp, EntityOpe
77
use crate::data::store::IntoEntityIterator;
88
use crate::prelude::ENV_VARS;
99
use crate::schema::InputSchema;
10-
use crate::util::lfu_cache::LfuCache;
10+
use crate::util::lfu_cache::{EvictStats, LfuCache};
1111

1212
use super::{DerivedEntityQuery, EntityType, LoadRelatedRequest, StoreError};
1313

@@ -58,6 +58,7 @@ impl Debug for EntityCache {
5858
pub struct ModificationsAndCache {
5959
pub modifications: Vec<s::EntityModification>,
6060
pub entity_lfu_cache: LfuCache<EntityKey, Option<Entity>>,
61+
pub evict_stats: EvictStats,
6162
}
6263

6364
impl EntityCache {
@@ -332,11 +333,14 @@ impl EntityCache {
332333
mods.push(modification)
333334
}
334335
}
335-
self.current.evict(ENV_VARS.mappings.entity_cache_size);
336+
let evict_stats = self
337+
.current
338+
.evict_and_stats(ENV_VARS.mappings.entity_cache_size);
336339

337340
Ok(ModificationsAndCache {
338341
modifications: mods,
339342
entity_lfu_cache: self.current,
343+
evict_stats,
340344
})
341345
}
342346
}

graph/src/util/lfu_cache.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,18 @@ impl<K: Clone + Ord + Eq + Hash + Debug + CacheWeight, V: CacheWeight + Default>
187187
self.queue.len()
188188
}
189189

190+
pub fn evict_and_stats(&mut self, max_weight: usize) -> EvictStats {
191+
self.evict_with_period(max_weight, STALE_PERIOD)
192+
.unwrap_or_else(|| EvictStats {
193+
new_weight: self.total_weight,
194+
evicted_weight: 0,
195+
new_count: self.len(),
196+
evicted_count: 0,
197+
stale_update: false,
198+
evict_time: Duration::from_millis(0),
199+
})
200+
}
201+
190202
/// Same as `evict_with_period(max_weight, STALE_PERIOD)`
191203
pub fn evict(&mut self, max_weight: usize) -> Option<EvictStats> {
192204
self.evict_with_period(max_weight, STALE_PERIOD)

0 commit comments

Comments
 (0)