Skip to content

Commit 7d8adb2

Browse files
committed
store: Make target duration for batch operations configurable
Also lower the default to 3 minutes; 5 minutes is too much on busy systems
1 parent 90654e5 commit 7d8adb2

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

docs/environment-variables.md

+4
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,7 @@ those.
200200
identified as unused, `graph-node` will wait at least this long before
201201
actually deleting the data (value is in minutes, defaults to 360, i.e. 6
202202
hours)
203+
- `GRAPH_STORE_BATCH_TARGET_DURATION`: How long batch operations during
204+
copying or grafting should take. This limits how long transactions for
205+
such long running operations will be, and therefore helps control bloat
206+
in other tables. Value is in seconds and defaults to 180s.

graph/src/env/store.rs

+8
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ pub struct EnvVarsStore {
8686
/// Setting this to `0` disables pipelined writes, and writes will be
8787
/// done synchronously.
8888
pub write_queue_size: usize,
89+
90+
/// How long batch operations during copying or grafting should take.
91+
/// Set by `GRAPH_STORE_BATCH_TARGET_DURATION` (expressed in seconds).
92+
/// The default is 180s.
93+
pub batch_target_duration: Duration,
8994
}
9095

9196
// This does not print any values avoid accidentally leaking any sensitive env vars
@@ -122,6 +127,7 @@ impl From<InnerStore> for EnvVarsStore {
122127
connection_min_idle: x.connection_min_idle,
123128
connection_idle_timeout: Duration::from_secs(x.connection_idle_timeout_in_secs),
124129
write_queue_size: x.write_queue_size,
130+
batch_target_duration: Duration::from_secs(x.batch_target_duration_in_secs),
125131
}
126132
}
127133
}
@@ -165,4 +171,6 @@ pub struct InnerStore {
165171
connection_idle_timeout_in_secs: u64,
166172
#[envconfig(from = "GRAPH_STORE_WRITE_QUEUE", default = "5")]
167173
write_queue_size: usize,
174+
#[envconfig(from = "GRAPH_STORE_BATCH_TARGET_DURATION", default = "180")]
175+
batch_target_duration_in_secs: u64,
168176
}

store/postgres/src/copy.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use diesel::{
3434
use graph::{
3535
components::store::EntityType,
3636
constraint_violation,
37-
prelude::{info, o, warn, BlockNumber, BlockPtr, Logger, StoreError},
37+
prelude::{info, o, warn, BlockNumber, BlockPtr, Logger, StoreError, ENV_VARS},
3838
};
3939

4040
use crate::{
@@ -51,7 +51,7 @@ const INITIAL_BATCH_SIZE: i64 = 10_000;
5151
/// arrays can be large and large arrays will slow down copying a lot. We
5252
/// therefore tread lightly in that case
5353
const INITIAL_BATCH_SIZE_LIST: i64 = 100;
54-
const TARGET_DURATION: Duration = Duration::from_secs(5 * 60);
54+
5555
const LOG_INTERVAL: Duration = Duration::from_secs(3 * 60);
5656

5757
/// If replicas are lagging by more than this, the copying code will pause
@@ -308,8 +308,9 @@ impl AdaptiveBatchSize {
308308
pub fn adapt(&mut self, duration: Duration) {
309309
// Avoid division by zero
310310
let duration = duration.as_millis().max(1);
311-
let new_batch_size =
312-
self.size as f64 * TARGET_DURATION.as_millis() as f64 / duration as f64;
311+
let new_batch_size = self.size as f64
312+
* ENV_VARS.store.batch_target_duration.as_millis() as f64
313+
/ duration as f64;
313314
self.size = (2 * self.size).min(new_batch_size.round() as i64);
314315
}
315316
}

0 commit comments

Comments
 (0)