From 42c017e8f02f1859ffdadcae4e3a6fe773811881 Mon Sep 17 00:00:00 2001 From: David Lutterkort Date: Tue, 3 May 2022 09:12:52 -0700 Subject: [PATCH] graphql: Use the correct setting for number of LfuCache shards This also makes it possible to turn the LfuCache off by setting GRAPH_QUERY_LFU_CACHE_SHARDS to 0 --- graph/src/env/graphql.rs | 2 +- graphql/src/execution/execution.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/graph/src/env/graphql.rs b/graph/src/env/graphql.rs index 9d7bbd05936..61296b92638 100644 --- a/graph/src/env/graphql.rs +++ b/graph/src/env/graphql.rs @@ -31,7 +31,7 @@ pub struct EnvVarsGraphQl { pub query_block_cache_shards: u8, /// Set by the environment variable `GRAPH_QUERY_LFU_CACHE_SHARDS`. The /// default value is set to whatever `GRAPH_QUERY_BLOCK_CACHE_SHARDS` is set - /// to. + /// to. Set to 0 to disable this cache. pub query_lfu_cache_shards: u8, /// How many blocks per network should be kept in the query cache. When the /// limit is reached, older blocks are evicted. This should be kept small diff --git a/graphql/src/execution/execution.rs b/graphql/src/execution/execution.rs index e7a5dd482d6..51fadb0bcc5 100644 --- a/graphql/src/execution/execution.rs +++ b/graphql/src/execution/execution.rs @@ -386,11 +386,11 @@ pub(crate) async fn execute_root_selection_set( if inserted { ctx.cache_status.store(CacheStatus::Insert); - } else { + } else if QUERY_LFU_CACHE.len() > 0 { // Results that are too old for the QUERY_BLOCK_CACHE go into the QUERY_LFU_CACHE + let shard = (key[0] as usize) % QUERY_LFU_CACHE.len(); let mut cache = QUERY_LFU_CACHE[shard].lock(&ctx.logger); - let max_mem = ENV_VARS.graphql.query_cache_max_mem - / (ENV_VARS.graphql.query_block_cache_shards as usize); + let max_mem = ENV_VARS.graphql.query_cache_max_mem / QUERY_LFU_CACHE.len(); cache.evict_with_period(max_mem, ENV_VARS.graphql.query_cache_stale_period); cache.insert( key,