Skip to content

Commit d6af534

Browse files
committed
core, graph: Perform eviction within the EntityCache
1 parent eaa3549 commit d6af534

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

core/src/subgraph/instance_manager.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ const BUFFERED_BLOCK_STREAM_SIZE: usize = 100;
3434
const BUFFERED_FIREHOSE_STREAM_SIZE: usize = 1;
3535

3636
lazy_static! {
37-
/// Size limit of the entity LFU cache, in bytes.
38-
// Multiplied by 1000 because the env var is in KB.
39-
pub static ref ENTITY_CACHE_SIZE: usize = 1000
40-
* std::env::var("GRAPH_ENTITY_CACHE_SIZE")
41-
.unwrap_or("10000".into())
42-
.parse::<usize>()
43-
.expect("invalid GRAPH_ENTITY_CACHE_SIZE");
44-
4537
// Keep deterministic errors non-fatal even if the subgraph is pending.
4638
// Used for testing Graph Node itself.
4739
pub static ref DISABLE_FAIL_FAST: bool =
@@ -1056,20 +1048,13 @@ async fn process_block<T: RuntimeHostBuilder<C>, C: Blockchain>(
10561048
let ModificationsAndCache {
10571049
modifications: mut mods,
10581050
data_sources,
1059-
entity_lfu_cache: mut cache,
1051+
entity_lfu_cache: cache,
10601052
} = block_state
10611053
.entity_cache
10621054
.as_modifications()
10631055
.map_err(|e| BlockProcessingError::Unknown(e.into()))?;
10641056
section.end();
10651057

1066-
let section = ctx
1067-
.host_metrics
1068-
.stopwatch
1069-
.start_section("entity_cache_evict");
1070-
cache.evict(*ENTITY_CACHE_SIZE);
1071-
section.end();
1072-
10731058
// Put the cache back in the ctx, asserting that the placeholder cache was not used.
10741059
assert!(ctx.state.entity_lfu_cache.is_empty());
10751060
ctx.state.entity_lfu_cache = cache;

graph/src/components/store.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ lazy_static! {
3737
)))
3838
.map(Duration::from_millis)
3939
.unwrap_or_else(|| Duration::from_millis(1000));
40+
41+
/// Size limit of the entity LFU cache, in bytes.
42+
// Multiplied by 1000 because the env var is in KB.
43+
pub static ref ENTITY_CACHE_SIZE: usize = 1000
44+
* std::env::var("GRAPH_ENTITY_CACHE_SIZE")
45+
.unwrap_or("10000".into())
46+
.parse::<usize>()
47+
.expect("invalid GRAPH_ENTITY_CACHE_SIZE");
4048
}
4149

4250
/// The type name of an entity. This is the string that is used in the
@@ -1643,6 +1651,8 @@ impl EntityCache {
16431651
mods.push(modification)
16441652
}
16451653
}
1654+
self.current.evict(*ENTITY_CACHE_SIZE);
1655+
16461656
Ok(ModificationsAndCache {
16471657
modifications: mods,
16481658
data_sources: self.data_sources,

0 commit comments

Comments
 (0)