perf(cmpp): isolate inbound transport capacity
This commit is contained in:
@@ -6,14 +6,24 @@ import { requestContext } from '../common/request-context';
|
||||
@Injectable()
|
||||
export class PrismaService extends PrismaClient implements OnModuleDestroy {
|
||||
constructor() {
|
||||
const databaseUrl = process.env.CMPP_PROCESS_ROLE === 'worker'
|
||||
const workerRole = process.env.CMPP_PROCESS_ROLE === 'worker';
|
||||
const databaseUrl = workerRole
|
||||
? process.env.API_WORKER_DATABASE_URL || process.env.DATABASE_URL
|
||||
: process.env.DATABASE_URL;
|
||||
const configuredPoolMax = Number(workerRole
|
||||
? process.env.API_WORKER_DB_POOL_MAX ?? 8
|
||||
: process.env.API_DB_POOL_MAX ?? 32);
|
||||
const poolMax = Number.isInteger(configuredPoolMax) && configuredPoolMax > 0
|
||||
? configuredPoolMax
|
||||
: workerRole ? 8 : 32;
|
||||
super({
|
||||
adapter: new PrismaPg(
|
||||
databaseUrl ??
|
||||
'postgresql://cmpp:cmpp_password@localhost:5432/cmpp_platform?schema=public',
|
||||
),
|
||||
adapter: new PrismaPg({
|
||||
connectionString: databaseUrl
|
||||
?? 'postgresql://cmpp:cmpp_password@localhost:5432/cmpp_platform?schema=public',
|
||||
// API capacity must be reserved independently from the heavier Worker
|
||||
// transactions; explicit bounds also protect PostgreSQL max_connections.
|
||||
max: poolMax,
|
||||
}),
|
||||
});
|
||||
const operationLog = this.operationLog;
|
||||
Object.defineProperty(this, 'operationLog', {
|
||||
|
||||
Reference in New Issue
Block a user