Skip to content

Commit

Permalink
graphql: Use the correct setting for number of LfuCache shards
Browse files Browse the repository at this point in the history
This also makes it possible to turn the LfuCache off by setting
GRAPH_QUERY_LFU_CACHE_SHARDS to 0
  • Loading branch information
lutter committed May 3, 2022
1 parent f84e6b8 commit 42c017e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion graph/src/env/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions graphql/src/execution/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,11 @@ pub(crate) async fn execute_root_selection_set<R: Resolver>(

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,
Expand Down

0 comments on commit 42c017e

Please sign in to comment.