diff --git a/src/config.ts b/src/config.ts index 1d5ed94..96d84d4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -76,8 +76,7 @@ addDefaults(config, { port: 5432, max: 10, idleTimeoutMillis: 10000, - maxTries: 3, - maxConcurrentRequests: 3500 + maxTries: 3 }, postgresReadOnly: { enabled: false, @@ -90,8 +89,7 @@ addDefaults(config, { max: 10, idleTimeoutMillis: 10000, maxTries: 3, - fallbackOnFail: true, - maxConcurrentRequests: 3500 + fallbackOnFail: true }, dumpDatabase: { enabled: false, diff --git a/src/databases/Postgres.ts b/src/databases/Postgres.ts index c10f094..6711897 100644 --- a/src/databases/Postgres.ts +++ b/src/databases/Postgres.ts @@ -33,9 +33,6 @@ export class Postgres implements IDatabase { private poolRead: Pool; private lastPoolReadFail = 0; - private concurrentRequests = 0; - private concurrentReadRequests = 0; - constructor(private config: DatabaseConfig) {} async init(): Promise { @@ -102,22 +99,6 @@ export class Postgres implements IDatabase { Logger.debug(`prepare (postgres): type: ${type}, query: ${query}, params: ${params}`); - if (this.config.readOnly) { - if (this.concurrentReadRequests > this.config.postgresReadOnly?.maxConcurrentRequests) { - Logger.error(`prepare (postgres): cancelling read query because too many concurrent requests, query: ${query}`); - throw new Error("Too many concurrent requests"); - } - - this.concurrentReadRequests++; - } else { - if (this.concurrentRequests > this.config.postgres.maxConcurrentRequests) { - Logger.error(`prepare (postgres): cancelling query because too many concurrent requests, query: ${query}`); - throw new Error("Too many concurrent requests"); - } - - this.concurrentRequests++; - } - const pendingQueries: PromiseWithState>[] = []; let tries = 0; let lastPool: Pool = null; @@ -134,12 +115,6 @@ export class Postgres implements IDatabase { if (options.useReplica && maxTries() - tries > 1) currentPromises.push(savePromiseState(timeoutPomise(this.config.postgresReadOnly.readTimeout))); const queryResult = await nextFulfilment(currentPromises); - if (this.config.readOnly) { - this.concurrentReadRequests--; - } else { - this.concurrentRequests--; - } - switch (type) { case "get": { const value = queryResult.rows[0]; @@ -167,12 +142,6 @@ export class Postgres implements IDatabase { } } while (this.isReadQuery(type) && tries < maxTries()); - if (this.config.readOnly) { - this.concurrentReadRequests--; - } else { - this.concurrentRequests--; - } - throw new Error(`prepare (postgres): ${type} ${query} failed after ${tries} tries`); } diff --git a/src/types/config.model.ts b/src/types/config.model.ts index e0498fb..e6b221d 100644 --- a/src/types/config.model.ts +++ b/src/types/config.model.ts @@ -15,7 +15,6 @@ interface RedisReadOnlyConfig extends redis.RedisClientOptions { export interface CustomPostgresConfig extends PoolConfig { enabled: boolean; maxTries: number; - maxConcurrentRequests: number; } export interface CustomPostgresReadOnlyConfig extends CustomPostgresConfig {