diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-05-30 08:10:46 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-05-30 12:27:59 -0400 |
| commit | b057d3be0de1de61c4a83e3b1d8c247df6240475 (patch) | |
| tree | dc6101f6315ddffe2c478ef6486e856ee75f506a | |
| parent | merge: Log config file paths at startup (!1066) (diff) | |
| download | sharkey-b057d3be0de1de61c4a83e3b1d8c247df6240475.tar.gz sharkey-b057d3be0de1de61c4a83e3b1d8c247df6240475.tar.bz2 sharkey-b057d3be0de1de61c4a83e3b1d8c247df6240475.zip | |
add slowQueryThreshold setting to configure slow query warning
| -rw-r--r-- | .config/ci.yml | 4 | ||||
| -rw-r--r-- | .config/cypress-devcontainer.yml | 4 | ||||
| -rw-r--r-- | .config/docker_example.yml | 4 | ||||
| -rw-r--r-- | .config/example.yml | 6 | ||||
| -rw-r--r-- | packages/backend/src/config.ts | 10 | ||||
| -rw-r--r-- | packages/backend/src/postgres.ts | 2 |
6 files changed, 25 insertions, 5 deletions
diff --git a/.config/ci.yml b/.config/ci.yml index 7d5261aacd..a1c8c23b44 100644 --- a/.config/ci.yml +++ b/.config/ci.yml @@ -115,6 +115,10 @@ db: user: postgres pass: ci + # Log a warning to the server console if any query takes longer than this to complete. + # Measured in milliseconds; set to 0 to disable. (default: 300) + slowQueryThreshold: 300 + # If false, then query results will be cached in redis. # If true (default), then queries will not be cached. # This will reduce database load at the cost of increased Redis traffic and risk of bugs and unpredictable behavior. diff --git a/.config/cypress-devcontainer.yml b/.config/cypress-devcontainer.yml index 51f408983c..97f78f3ccc 100644 --- a/.config/cypress-devcontainer.yml +++ b/.config/cypress-devcontainer.yml @@ -57,6 +57,10 @@ db: user: postgres pass: postgres + # Log a warning to the server console if any query takes longer than this to complete. + # Measured in milliseconds; set to 0 to disable. (default: 300) + slowQueryThreshold: 300 + # If false, then query results will be cached in redis. # If true (default), then queries will not be cached. # This will reduce database load at the cost of increased Redis traffic and risk of bugs and unpredictable behavior. diff --git a/.config/docker_example.yml b/.config/docker_example.yml index 1b55eee7f5..051526024e 100644 --- a/.config/docker_example.yml +++ b/.config/docker_example.yml @@ -118,6 +118,10 @@ db: user: example-misskey-user pass: example-misskey-pass + # Log a warning to the server console if any query takes longer than this to complete. + # Measured in milliseconds; set to 0 to disable. (default: 300) + slowQueryThreshold: 300 + # If false, then query results will be cached in redis. # If true (default), then queries will not be cached. # This will reduce database load at the cost of increased Redis traffic and risk of bugs and unpredictable behavior. diff --git a/.config/example.yml b/.config/example.yml index b7843da9ad..7d9b6ceda6 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -121,13 +121,15 @@ db: user: sharkey pass: example-misskey-pass + # Log a warning to the server console if any query takes longer than this to complete. + # Measured in milliseconds; set to 0 to disable. (default: 300) + slowQueryThreshold: 300 + # If false, then query results will be cached in redis. # If true (default), then queries will not be cached. # This will reduce database load at the cost of increased Redis traffic and risk of bugs and unpredictable behavior. #disableCache: false - # - # Extra Connection options #extra: # ssl: true diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index d61112ae40..c2e7efd456 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -41,6 +41,7 @@ type Source = { db?: string; user?: string; pass?: string; + slowQueryThreshold?: number; disableCache?: boolean; extra?: { [x: string]: string }; }; @@ -225,6 +226,7 @@ export type Config = { db: string; user: string; pass: string; + slowQueryThreshold?: number; disableCache?: boolean; extra?: { [x: string]: string }; }; @@ -411,6 +413,10 @@ export function loadConfig(): Config { const internalMediaProxy = `${scheme}://${host}/proxy`; const redis = convertRedisOptions(config.redis, host); + // nullish => 300 (default) + // 0 => undefined (disabled) + const slowQueryThreshold = (config.db.slowQueryThreshold ?? 300) || undefined; + return { version, publishTarballInsteadOfProvideRepositoryUrl: !!config.publishTarballInsteadOfProvideRepositoryUrl, @@ -429,7 +435,7 @@ export function loadConfig(): Config { apiUrl: `${scheme}://${host}/api`, authUrl: `${scheme}://${host}/auth`, driveUrl: `${scheme}://${host}/files`, - db: { ...config.db, db: dbDb, user: dbUser, pass: dbPass }, + db: { ...config.db, db: dbDb, user: dbUser, pass: dbPass, slowQueryThreshold }, dbReplications: config.dbReplications, dbSlaves: config.dbSlaves, fulltextSearch: config.fulltextSearch, @@ -637,7 +643,7 @@ function applyEnvOverrides(config: Source) { // these are all the settings that can be overridden _apply_top([['url', 'port', 'address', 'socket', 'chmodSocket', 'disableHsts', 'id', 'dbReplications', 'websocketCompression']]); - _apply_top(['db', ['host', 'port', 'db', 'user', 'pass', 'disableCache']]); + _apply_top(['db', ['host', 'port', 'db', 'user', 'pass', 'slowQueryThreshold', 'disableCache']]); _apply_top(['dbSlaves', Array.from((config.dbSlaves ?? []).keys()), ['host', 'port', 'db', 'user', 'pass']]); _apply_top([ ['redis', 'redisForPubsub', 'redisForJobQueue', 'redisForTimelines', 'redisForReactions', 'redisForRateLimit'], diff --git a/packages/backend/src/postgres.ts b/packages/backend/src/postgres.ts index 34fca6dd92..eed60dd499 100644 --- a/packages/backend/src/postgres.ts +++ b/packages/backend/src/postgres.ts @@ -321,7 +321,7 @@ export function createPostgresDataSource(config: Config) { printReplicationMode: !!config.dbReplications, }) : undefined, - maxQueryExecutionTime: 300, + maxQueryExecutionTime: config.db.slowQueryThreshold, entities: entities, migrations: ['../../migration/*.js'], }); |