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

feat(DB): Chunk SQL Inserts #68

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions defaults.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ CHAINGRAPH_POSTGRES_MAX_CONNECTIONS=
# In real-world testing, this usually reduces the speed of Chaingraph's initial sync, so Chaingraph leaves "synchronous_commit = on" by default.
CHAINGRAPH_POSTGRES_SYNCHRONOUS_COMMIT=true

# The target size (in MB) for each INSERT query chunk sent to Postgres.
# During initial sync, the transactions of each block will be inserted into the DB. This value specifies the target size of each INSERT query chunk to prevent excessivley large queries on large blocks.
# Setting to a low value (e.g. 1MB) will allow Chaingraph to perform initial sync on memory constrained devices/servers.
CHAINGRAPH_POSTGRES_INSERT_CHUNK_SIZE_MB=32

# The target size (in MB) of the buffer which holds downloaded blocks waiting to be saved to the database. This primarily affects memory usage during the initial chain sync.
# For best performance, this should be around `CHAINGRAPH_POSTGRES_MAX_CONNECTIONS * maximum block size`, while leaving enough memory available to the host machine. If not set, Chaingraph will measure free memory at startup and attempt to select a reasonable value.
CHAINGRAPH_BLOCK_BUFFER_TARGET_SIZE_MB=
Expand Down
12 changes: 12 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const expectedOptions = [
'CHAINGRAPH_POSTGRES_CONNECTION_STRING',
'CHAINGRAPH_POSTGRES_MAX_CONNECTIONS',
'CHAINGRAPH_POSTGRES_SYNCHRONOUS_COMMIT',
'CHAINGRAPH_POSTGRES_INSERT_CHUNK_SIZE_MB',
'CHAINGRAPH_TRUSTED_NODES',
'CHAINGRAPH_USER_AGENT',
'NODE_ENV',
Expand Down Expand Up @@ -362,6 +363,17 @@ const chaingraphUserAgent =
const postgresSynchronousCommit =
configuration.CHAINGRAPH_POSTGRES_SYNCHRONOUS_COMMIT !== 'false';

/**
* Set via the `CHAINGRAPH_POSTGRES_INSERT_CHUNK_SIZE_MB` environment variable.
*/
const postgresInsertChunkSizeMbValue = Number(
configuration.CHAINGRAPH_POSTGRES_INSERT_CHUNK_SIZE_MB
);
if (isNaN(postgresInsertChunkSizeMbValue)) {
// eslint-disable-next-line functional/no-throw-statement
throw new Error('CHAINGRAPH_POSTGRES_INSERT_CHUNK_SIZE_MB must be a number.');
}

/**
* `true` if the `NODE_ENV` environment variable is `production`.
*/
Expand Down
Loading