Skip to content

Commit 4d9d196

Browse files
fix(javascript/ditsmod-bun): fixed cluster mode for ditsmod-bun. (#7993)
1 parent 8cba03e commit 4d9d196

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

javascript/ditsmod-bun/cluster.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

javascript/ditsmod-bun/src/main.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
import { Application } from '@ditsmod/core';
1+
import cluster from 'node:cluster';
22
import type { ServerOptions } from 'node:http';
3+
import { availableParallelism } from 'node:os';
4+
import { Application } from '@ditsmod/core';
35

46
import { AppModule } from './app/app.module.js';
57

6-
const serverOptions: ServerOptions = { keepAlive: true, keepAliveTimeout: 0 };
7-
const app = await new Application().bootstrap(AppModule, { serverOptions });
8-
app.server.listen(3000, '0.0.0.0');
8+
const numCpus = availableParallelism();
9+
10+
if (numCpus > 1 && cluster.isPrimary) {
11+
for (let i = 0; i < numCpus; i++) {
12+
cluster.fork();
13+
}
14+
} else {
15+
const serverOptions: ServerOptions = { keepAlive: true, keepAliveTimeout: 0 };
16+
const app = await new Application().bootstrap(AppModule, { serverOptions });
17+
app.server.listen(3000, '0.0.0.0');
18+
}

0 commit comments

Comments
 (0)