Skip to content

Commit 0a0e12b

Browse files
committed
more intelligent database connections management
1 parent d1527cb commit 0a0e12b

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

apps/server/src/core/database/database.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import { readFile } from "node:fs/promises";
2+
import { isMainThread } from "node:worker_threads";
23
import { drizzle } from "drizzle-orm/postgres-js";
34
import postgres from "postgres";
45

56
import * as schema from "./schema.js";
67

8+
const SERVER_POOL_MAX = 32;
9+
const WORKER_POOL_MAX = 16;
10+
const IDLE_TIMEOUT_SECONDS = 30;
11+
712
let PG_PASSWORD = process.env.PG_PASSWORD;
813

914
const PG_PASSWORD_FILE = process.env.PG_PASSWORD_FILE;
@@ -17,8 +22,8 @@ const connection = postgres({
1722
password: PG_PASSWORD,
1823
database: process.env.PG_DATABASE,
1924
path: process.env.PG_PATH,
20-
max: 25,
21-
idle_timeout: 120,
25+
max: isMainThread ? SERVER_POOL_MAX : WORKER_POOL_MAX,
26+
idle_timeout: IDLE_TIMEOUT_SECONDS,
2227
});
2328

2429
export const database = drizzle(connection, {

apps/server/src/vehicle-handling/handle-vehicle-batch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function handleVehicleBatch(vehicleJourneys: VehicleJourney[]) {
8080
}
8181

8282
if (network.hasVehiclesFeature) {
83-
registerActivities(registerableActivities);
83+
await registerActivities(registerableActivities);
8484
}
8585
}
8686

0 commit comments

Comments
 (0)