fix: cap postgres connection pools
This commit is contained in:
@@ -41,6 +41,7 @@ interface RuntimeConfig {
|
||||
baiduNetdiskInternalUrl: string;
|
||||
microservices: MicroserviceConfig[];
|
||||
logFile: string;
|
||||
databasePoolMax: number;
|
||||
}
|
||||
|
||||
interface MicroserviceConfig {
|
||||
@@ -204,9 +205,10 @@ const serviceStartedAt = new Date();
|
||||
const config = readConfig();
|
||||
const logger = createLogger("backend-core", config.logFile);
|
||||
const sql = postgres(config.databaseUrl, {
|
||||
max: 8,
|
||||
max: config.databasePoolMax,
|
||||
idle_timeout: 20,
|
||||
connect_timeout: 10,
|
||||
connection: { application_name: "unidesk-backend-core" },
|
||||
});
|
||||
|
||||
let dbReady = false;
|
||||
@@ -363,6 +365,7 @@ function readConfig(): RuntimeConfig {
|
||||
baiduNetdiskInternalUrl: process.env.BAIDU_NETDISK_INTERNAL_URL || "http://baidu-netdisk:4244",
|
||||
microservices: readMicroservicesEnv(),
|
||||
logFile: requiredEnv("LOG_FILE"),
|
||||
databasePoolMax: Math.max(1, Math.min(16, readOptionalNumberEnv("DATABASE_POOL_MAX", 4))),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user