perf: 프로필 DB 풀과 advisory lock 격리
역할별 PostgreSQL pool 상한과 동일 process 공유 pool을 적용하고 health 지표를 노출한다.\n\n게임 기능 advisory lock을 schema namespace로 통일하고 실제 PostgreSQL 통합 하네스를 보강한다.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import { sanitizeManagedProcessEnv } from '@sammo-ts/gateway-api';
|
||||
import { resolvePostgresPoolMax } from '@sammo-ts/infra';
|
||||
|
||||
const parsePositiveInt = (value: string | undefined, fallback: number, name: string): number => {
|
||||
if (!value) return fallback;
|
||||
@@ -25,6 +26,7 @@ export interface ReleaseControllerConfig {
|
||||
gatewayBasePath: string;
|
||||
pollIntervalMs: number;
|
||||
readinessTimeoutMs: number;
|
||||
postgresPoolMax: number;
|
||||
baseEnv: Record<string, string>;
|
||||
}
|
||||
|
||||
@@ -54,6 +56,7 @@ export const resolveReleaseControllerConfig = (env: NodeJS.ProcessEnv = process.
|
||||
60000,
|
||||
'RELEASE_CONTROLLER_READINESS_TIMEOUT_MS'
|
||||
),
|
||||
postgresPoolMax: resolvePostgresPoolMax(env.RELEASE_CONTROLLER_POSTGRES_POOL_MAX ?? env.POSTGRES_POOL_MAX, 2),
|
||||
baseEnv: {
|
||||
...sanitizeManagedProcessEnv(env),
|
||||
REDIS_URL: env.REDIS_URL.trim(),
|
||||
|
||||
@@ -16,7 +16,10 @@ export * from './selfUpgrade.js';
|
||||
|
||||
const main = async (): Promise<void> => {
|
||||
const config = resolveReleaseControllerConfig();
|
||||
const postgres = createGatewayPostgresConnector({ url: config.gatewayDatabaseUrl });
|
||||
const postgres = createGatewayPostgresConnector({
|
||||
url: config.gatewayDatabaseUrl,
|
||||
maxConnections: config.postgresPoolMax,
|
||||
});
|
||||
await postgres.connect();
|
||||
const repository = createGatewayReleaseRepository(postgres.prisma as GatewayPrismaClient);
|
||||
const workspaceManager = new GitWorkspaceManager({
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
readReleaseManifest,
|
||||
sanitizeManagedProcessEnv,
|
||||
} from '@sammo-ts/gateway-api';
|
||||
import { resolvePostgresPoolMax } from '@sammo-ts/infra';
|
||||
|
||||
import type { ReleaseControllerConfig } from './config.js';
|
||||
|
||||
@@ -25,6 +26,9 @@ const HEARTBEAT_INTERVAL_MS = 60_000;
|
||||
const PROCESS_NAMES = ['sammo:gateway-api', 'sammo:gateway-frontend', 'sammo:gateway-orchestrator'] as const;
|
||||
const SENSITIVE_ENV_NAME = /(SECRET|TOKEN|PASSWORD|PASSWD|PRIVATE_KEY|CLIENT_SECRET|DATABASE_URL|REDIS_URL)/iu;
|
||||
|
||||
const managedPostgresPoolMax = (env: Record<string, string>, roleVariable: string, fallback: number): string =>
|
||||
String(resolvePostgresPoolMax(env[roleVariable] ?? env.POSTGRES_POOL_MAX, fallback));
|
||||
|
||||
const buildGatewayReleaseCommands = (
|
||||
workspaceRoot: string,
|
||||
needsInstall: boolean,
|
||||
@@ -78,7 +82,16 @@ export const buildGatewayProcessDefinitions = (
|
||||
GATEWAY_DATABASE_URL: config.gatewayDatabaseUrl,
|
||||
};
|
||||
return [
|
||||
{ name: 'sammo:gateway-api', script: apiScript, cwd: apiCwd, env: { ...env, GATEWAY_ROLE: 'api' } },
|
||||
{
|
||||
name: 'sammo:gateway-api',
|
||||
script: apiScript,
|
||||
cwd: apiCwd,
|
||||
env: {
|
||||
...env,
|
||||
POSTGRES_POOL_MAX: managedPostgresPoolMax(config.baseEnv, 'GATEWAY_API_POSTGRES_POOL_MAX', 4),
|
||||
GATEWAY_ROLE: 'api',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'sammo:gateway-frontend',
|
||||
script: frontendScript,
|
||||
@@ -90,7 +103,11 @@ export const buildGatewayProcessDefinitions = (
|
||||
name: 'sammo:gateway-orchestrator',
|
||||
script: apiScript,
|
||||
cwd: apiCwd,
|
||||
env: { ...env, GATEWAY_ROLE: 'orchestrator' },
|
||||
env: {
|
||||
...env,
|
||||
POSTGRES_POOL_MAX: managedPostgresPoolMax(config.baseEnv, 'GATEWAY_ORCHESTRATOR_POSTGRES_POOL_MAX', 2),
|
||||
GATEWAY_ROLE: 'orchestrator',
|
||||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
@@ -41,6 +41,7 @@ export const buildReleaseControllerDefinition = (
|
||||
...sanitizeManagedProcessEnv(config.baseEnv),
|
||||
GATEWAY_DATABASE_URL: config.gatewayDatabaseUrl,
|
||||
GATEWAY_DB_SCHEMA: config.gatewayDbSchema,
|
||||
POSTGRES_POOL_MAX: String(config.postgresPoolMax),
|
||||
RELEASE_CONTROLLER_WORKSPACE_ROOT: config.workspaceRoot,
|
||||
RELEASE_CONTROLLER_WORKTREE_ROOT: config.worktreeRoot,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user