Skip to content

Commit 4629cb3

Browse files
authored
Updated brahma-firelight with CLUSTER mode (#10261)
* brahma-firelight added * cluster mode enabled
1 parent 1231b12 commit 4629cb3

File tree

5 files changed

+78
-41
lines changed

5 files changed

+78
-41
lines changed
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
{
22
"framework": "brahma-firelight",
3-
"tests": [{
4-
"default": {
5-
"json_url": "/json",
6-
"plaintext_url": "/plaintext",
7-
"port": 8080,
8-
"approach": "Realistic",
9-
"classification": "Micro",
10-
"framework": "brahma-firelight",
11-
"language": "TypeScript",
12-
"flavor": "bun",
13-
"platform": "bun",
14-
"webserver": "None",
15-
"os": "Linux",
16-
"database_os": "Linux",
17-
"display_name": "brahma-firelight",
18-
"versus": "nodejs"
3+
"tests": [
4+
{
5+
"default": {
6+
"json_url": "/json",
7+
"plaintext_url": "/plaintext",
8+
"port": 8080,
9+
"approach": "Realistic",
10+
"classification": "Micro",
11+
"framework": "brahma-firelight",
12+
"language": "TypeScript",
13+
"flavor": "bun",
14+
"platform": "bun",
15+
"webserver": "None",
16+
"os": "Linux",
17+
"database_os": "Linux",
18+
"display_name": "brahma-firelight",
19+
"versus": "nodejs"
20+
}
1921
}
20-
}]
22+
]
2123
}
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
FROM oven/bun:1.3
2-
1+
FROM oven/bun:1.3 AS builder
32
WORKDIR /app
43

5-
COPY . .
4+
COPY package.json bun.lock ./
65

7-
RUN bun install
6+
RUN bun ci
87

8+
COPY . .
99
RUN bun run build
1010

11+
FROM oven/bun:1.3 AS runtime
12+
WORKDIR /app
13+
14+
ENV NODE_ENV=production
15+
ENV PORT=8080
16+
17+
COPY --from=builder /app/dist ./dist
18+
COPY --from=builder /app/node_modules ./node_modules
19+
COPY --from=builder /app/package.json ./package.json
20+
21+
ENV NODE_ENV=production
22+
1123
EXPOSE 8080
1224

13-
CMD ["bun", "dist/main.js"]
25+
ENTRYPOINT ["bun", "dist/main.js"]

frameworks/TypeScript/brahma-firelight/bun.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"": {
55
"name": "brahma-firelight",
66
"dependencies": {
7-
"brahma-firelight": "1.5.16",
7+
"brahma-firelight": "^1.5.18",
88
},
99
"devDependencies": {
1010
"@types/bun": "latest",
@@ -21,7 +21,7 @@
2121

2222
"@types/react": ["@types/[email protected]", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="],
2323

24-
"brahma-firelight": ["[email protected].16", "", {}, "sha512-KwqrG3EHBcEYiOjjx7UvZ4TDxnKTP+DPjnQQqblKuHQcS/mw35NzIYf01YnBZLRM/9VZrb5+UrDaNmrAPZGYlw=="],
24+
"brahma-firelight": ["[email protected].18", "", {}, "sha512-/raDDeb6/AAHYPfvTi4vWA79BjsHwh5Eg63GWJPwWzyip3mvY0tIsNeMqHit4XBdyJZ9t0UgtsvNaHGx3zqFGw=="],
2525

2626
"bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-NMrcy7smratanWJ2mMXdpatalovtxVggkj11bScuWuiOoXTiKIu2eVS1/7qbyI/4yHedtsn175n4Sm4JcdHLXw=="],
2727

frameworks/TypeScript/brahma-firelight/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"typescript": "^5"
1515
},
1616
"dependencies": {
17-
"brahma-firelight": "1.5.16"
17+
"brahma-firelight": "^1.5.18"
1818
}
1919
}
Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { createApp, type Response, type Request, type App, type NextFunction, type Handler } from "brahma-firelight";
2+
import cluster from "node:cluster";
3+
import os from "node:os";
24

35
const app: App = createApp();
46

57
// Server Config Middleware
68
const serverInfo: Handler = (_req: Request, res: Response, next?: NextFunction) => {
79
res.setHeader("Server", "brahma-firelight");
10+
res.setHeader("Connection", "keep-alive")
811
next?.();
912
};
1013

@@ -19,19 +22,39 @@ app.get("/plaintext", serverInfo, (_req: Request, res: Response) => {
1922
});
2023

2124
// Port & Host
22-
23-
app.listen("0.0.0.0", 8080);
24-
25-
// Enable built in Graceful Shutdown (optional for production use)
26-
27-
process.on('SIGINT', async () => {
28-
console.log('SIGINT → shutting down...');
29-
await app.close(2000); // wait up to 2s for requests
30-
process.exit(0);
31-
});
32-
33-
process.on('SIGTERM', async () => {
34-
console.log('SIGTERM → shutting down...');
35-
await app.close(2000);
36-
process.exit(0);
37-
});
25+
const PORT = process.env.PORT || 8080;
26+
const HOST = process.env.HOST || "0.0.0.0";
27+
28+
// Single CORE
29+
//app.listen(HOST, +PORT);
30+
31+
// Multi CORE (cluster with max cpus available)
32+
if (cluster.isPrimary) {
33+
const cpuCount = os.cpus().length;
34+
console.log(`Primary ${process.pid} running → forking ${cpuCount} workers...`);
35+
36+
for (let i = 0; i < cpuCount; i++) {
37+
cluster.fork();
38+
}
39+
40+
cluster.on("exit", (worker) => {
41+
console.log(`Worker ${worker.process.pid} died → restarting...`);
42+
cluster.fork();
43+
});
44+
} else {
45+
app.listen(HOST, +PORT);
46+
}
47+
48+
// // Enable built in Graceful Shutdown (optional for production use)
49+
50+
// process.on('SIGINT', async () => {
51+
// console.log('SIGINT → shutting down...');
52+
// await app.close(2000); // wait up to 2s for requests
53+
// process.exit(0);
54+
// });
55+
56+
// process.on('SIGTERM', async () => {
57+
// console.log('SIGTERM → shutting down...');
58+
// await app.close(2000);
59+
// process.exit(0);
60+
// });

0 commit comments

Comments
 (0)