Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache recent blocks in memory to reduce load on the db #4215

Merged
merged 7 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions graph/src/env/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ pub struct EnvVarsStore {
/// Set by the environment variable `GRAPH_REMOVE_UNUSED_INTERVAL`
/// (expressed in minutes). The default value is 360 minutes.
pub remove_unused_interval: chrono::Duration,
/// Set by the environment variable
/// `GRAPH_STORE_RECENT_BLOCKS_CACHE_CAPACITY`. The default value is 10 blocks.
pub recent_blocks_cache_capacity: usize,

// These should really be set through the configuration file, especially for
// `GRAPH_STORE_CONNECTION_MIN_IDLE` and
Expand Down Expand Up @@ -123,6 +126,7 @@ impl From<InnerStore> for EnvVarsStore {
remove_unused_interval: chrono::Duration::minutes(
x.remove_unused_interval_in_minutes as i64,
),
recent_blocks_cache_capacity: x.recent_blocks_cache_capacity,
connection_timeout: Duration::from_millis(x.connection_timeout_in_millis),
connection_min_idle: x.connection_min_idle,
connection_idle_timeout: Duration::from_secs(x.connection_idle_timeout_in_secs),
Expand Down Expand Up @@ -158,6 +162,8 @@ pub struct InnerStore {
connection_try_always: EnvVarBoolean,
#[envconfig(from = "GRAPH_REMOVE_UNUSED_INTERVAL", default = "360")]
remove_unused_interval_in_minutes: u64,
#[envconfig(from = "GRAPH_STORE_RECENT_BLOCKS_CACHE_CAPACITY", default = "10")]
recent_blocks_cache_capacity: usize,

// These should really be set through the configuration file, especially for
// `GRAPH_STORE_CONNECTION_MIN_IDLE` and
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.65.0"
channel = "1.66.0"
profile = "default"
3 changes: 2 additions & 1 deletion store/postgres/src/block_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
use graph::{
blockchain::ChainIdentifier,
components::store::BlockStore as BlockStoreTrait,
prelude::{error, warn, BlockNumber, BlockPtr, Logger},
prelude::{error, warn, BlockNumber, BlockPtr, Logger, ENV_VARS},
};
use graph::{
constraint_violation,
Expand Down Expand Up @@ -372,6 +372,7 @@ impl BlockStore {
status,
sender,
pool,
ENV_VARS.store.recent_blocks_cache_capacity,
);
if create {
store.create(&ident)?;
Expand Down
Loading