mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 12:07:07 +03:00
Add max active postgres requests
This commit is contained in:
@@ -76,7 +76,8 @@ addDefaults(config, {
|
|||||||
port: 5432,
|
port: 5432,
|
||||||
max: 10,
|
max: 10,
|
||||||
idleTimeoutMillis: 10000,
|
idleTimeoutMillis: 10000,
|
||||||
maxTries: 3
|
maxTries: 3,
|
||||||
|
maxActiveRequests: -1
|
||||||
},
|
},
|
||||||
postgresReadOnly: {
|
postgresReadOnly: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { IDatabase, QueryOption, QueryType } from "./IDatabase";
|
|||||||
import { Client, Pool, QueryResult, types } from "pg";
|
import { Client, Pool, QueryResult, types } from "pg";
|
||||||
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import { CustomPostgresConfig, CustomPostgresReadOnlyConfig } from "../types/config.model";
|
import { CustomPostgresReadOnlyConfig, CustomWritePostgresConfig } from "../types/config.model";
|
||||||
import { timeoutPomise, PromiseWithState, savePromiseState, nextFulfilment } from "../utils/promise";
|
import { timeoutPomise, PromiseWithState, savePromiseState, nextFulfilment } from "../utils/promise";
|
||||||
|
|
||||||
// return numeric (pg_type oid=1700) as float
|
// return numeric (pg_type oid=1700) as float
|
||||||
@@ -22,7 +22,7 @@ export interface DatabaseConfig {
|
|||||||
fileNamePrefix: string,
|
fileNamePrefix: string,
|
||||||
readOnly: boolean,
|
readOnly: boolean,
|
||||||
createDbIfNotExists: boolean,
|
createDbIfNotExists: boolean,
|
||||||
postgres: CustomPostgresConfig,
|
postgres: CustomWritePostgresConfig,
|
||||||
postgresReadOnly: CustomPostgresReadOnlyConfig
|
postgresReadOnly: CustomPostgresReadOnlyConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +105,10 @@ export class Postgres implements IDatabase {
|
|||||||
|
|
||||||
Logger.debug(`prepare (postgres): type: ${type}, query: ${query}, params: ${params}`);
|
Logger.debug(`prepare (postgres): type: ${type}, query: ${query}, params: ${params}`);
|
||||||
|
|
||||||
|
if (this.activePostgresRequests > this.config.postgres.maxActiveRequests) {
|
||||||
|
throw new Error("Too many active postgres requests");
|
||||||
|
}
|
||||||
|
|
||||||
const pendingQueries: PromiseWithState<QueryResult<any>>[] = [];
|
const pendingQueries: PromiseWithState<QueryResult<any>>[] = [];
|
||||||
let tries = 0;
|
let tries = 0;
|
||||||
let lastPool: Pool = null;
|
let lastPool: Pool = null;
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ export interface CustomPostgresConfig extends PoolConfig {
|
|||||||
maxTries: number;
|
maxTries: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface CustomWritePostgresConfig extends CustomPostgresConfig {
|
||||||
|
maxActiveRequests: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface CustomPostgresReadOnlyConfig extends CustomPostgresConfig {
|
export interface CustomPostgresReadOnlyConfig extends CustomPostgresConfig {
|
||||||
weight: number;
|
weight: number;
|
||||||
readTimeout: number;
|
readTimeout: number;
|
||||||
@@ -71,7 +75,7 @@ export interface SBSConfig {
|
|||||||
redisRead?: RedisReadOnlyConfig;
|
redisRead?: RedisReadOnlyConfig;
|
||||||
redisRateLimit: boolean;
|
redisRateLimit: boolean;
|
||||||
maxRewardTimePerSegmentInSeconds?: number;
|
maxRewardTimePerSegmentInSeconds?: number;
|
||||||
postgres?: CustomPostgresConfig;
|
postgres?: CustomWritePostgresConfig;
|
||||||
postgresReadOnly?: CustomPostgresReadOnlyConfig;
|
postgresReadOnly?: CustomPostgresReadOnlyConfig;
|
||||||
dumpDatabase?: DumpDatabase;
|
dumpDatabase?: DumpDatabase;
|
||||||
diskCacheURL: string;
|
diskCacheURL: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user