Revert "Add concurrent request limit"

This commit is contained in:
Ajay
2022-10-11 11:59:53 -04:00
parent eb3d733a34
commit 415bb31e36
3 changed files with 2 additions and 36 deletions

View File

@@ -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,

View File

@@ -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<void> {
@@ -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<QueryResult<any>>[] = [];
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`);
}

View File

@@ -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 {