perf(cmpp): isolate inbound transport capacity

This commit is contained in:
hectorzhao
2026-08-20 18:09:29 +08:00
parent 53073461e9
commit 6708f1f7c5
11 changed files with 95 additions and 8 deletions
+15 -5
View File
@@ -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', {