Pārlūkot izejas kodu

Updated brahma-firelight with CLUSTER mode (#10261)

* brahma-firelight added

* cluster mode enabled
Shyam 1 mēnesi atpakaļ
vecāks
revīzija
4629cb3318

+ 19 - 17
frameworks/TypeScript/brahma-firelight/benchmark_config.json

@@ -1,21 +1,23 @@
 {
   "framework": "brahma-firelight",
-  "tests": [{
-    "default": {
-      "json_url": "/json",
-      "plaintext_url": "/plaintext",
-      "port": 8080,
-      "approach": "Realistic",
-      "classification": "Micro",
-      "framework": "brahma-firelight",
-      "language": "TypeScript",
-      "flavor": "bun",
-      "platform": "bun",
-      "webserver": "None",
-      "os": "Linux",
-      "database_os": "Linux",
-      "display_name": "brahma-firelight",
-      "versus": "nodejs"
+  "tests": [
+    {
+      "default": {
+        "json_url": "/json",
+        "plaintext_url": "/plaintext",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "Micro",
+        "framework": "brahma-firelight",
+        "language": "TypeScript",
+        "flavor": "bun",
+        "platform": "bun",
+        "webserver": "None",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "brahma-firelight",
+        "versus": "nodejs"
+      }
     }
-  }]
+  ]
 }

+ 17 - 5
frameworks/TypeScript/brahma-firelight/brahma-firelight.dockerfile

@@ -1,13 +1,25 @@
-FROM oven/bun:1.3
-
+FROM oven/bun:1.3 AS builder
 WORKDIR /app
 
-COPY . .
+COPY package.json bun.lock ./
 
-RUN bun install
+RUN bun ci
 
+COPY . .
 RUN bun run build
 
+FROM oven/bun:1.3 AS runtime
+WORKDIR /app
+
+ENV NODE_ENV=production
+ENV PORT=8080
+
+COPY --from=builder /app/dist ./dist
+COPY --from=builder /app/node_modules ./node_modules
+COPY --from=builder /app/package.json ./package.json
+
+ENV NODE_ENV=production
+
 EXPOSE 8080
 
-CMD ["bun", "dist/main.js"]
+ENTRYPOINT ["bun", "dist/main.js"]

+ 2 - 2
frameworks/TypeScript/brahma-firelight/bun.lock

@@ -4,7 +4,7 @@
     "": {
       "name": "brahma-firelight",
       "dependencies": {
-        "brahma-firelight": "1.5.16",
+        "brahma-firelight": "^1.5.18",
       },
       "devDependencies": {
         "@types/bun": "latest",
@@ -21,7 +21,7 @@
 
     "@types/react": ["@types/[email protected]", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="],
 
-    "brahma-firelight": ["[email protected]6", "", {}, "sha512-KwqrG3EHBcEYiOjjx7UvZ4TDxnKTP+DPjnQQqblKuHQcS/mw35NzIYf01YnBZLRM/9VZrb5+UrDaNmrAPZGYlw=="],
+    "brahma-firelight": ["[email protected]8", "", {}, "sha512-/raDDeb6/AAHYPfvTi4vWA79BjsHwh5Eg63GWJPwWzyip3mvY0tIsNeMqHit4XBdyJZ9t0UgtsvNaHGx3zqFGw=="],
 
     "bun-types": ["[email protected]", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-NMrcy7smratanWJ2mMXdpatalovtxVggkj11bScuWuiOoXTiKIu2eVS1/7qbyI/4yHedtsn175n4Sm4JcdHLXw=="],
 

+ 1 - 1
frameworks/TypeScript/brahma-firelight/package.json

@@ -14,6 +14,6 @@
     "typescript": "^5"
   },
   "dependencies": {
-    "brahma-firelight": "1.5.16"
+    "brahma-firelight": "^1.5.18"
   }
 }

+ 39 - 16
frameworks/TypeScript/brahma-firelight/src/main.ts

@@ -1,10 +1,13 @@
 import { createApp, type Response, type Request, type App, type NextFunction, type Handler } from "brahma-firelight";
+import cluster from "node:cluster";
+import os from "node:os";
 
 const app: App = createApp();
 
 // Server Config Middleware
 const serverInfo: Handler = (_req: Request, res: Response, next?: NextFunction) => {
     res.setHeader("Server", "brahma-firelight");
+    res.setHeader("Connection", "keep-alive")
     next?.();
 };
 
@@ -19,19 +22,39 @@ app.get("/plaintext", serverInfo, (_req: Request, res: Response) => {
 });
 
 // Port & Host 
-
-app.listen("0.0.0.0", 8080);
-
-// Enable built in Graceful Shutdown (optional for production use)
-
-process.on('SIGINT', async () => {
-    console.log('SIGINT → shutting down...');
-    await app.close(2000); // wait up to 2s for requests
-    process.exit(0);
-});
-
-process.on('SIGTERM', async () => {
-    console.log('SIGTERM → shutting down...');
-    await app.close(2000);
-    process.exit(0);
-});
+const PORT = process.env.PORT || 8080;
+const HOST = process.env.HOST || "0.0.0.0";
+
+// Single CORE
+//app.listen(HOST, +PORT);
+
+// Multi CORE (cluster with max cpus available)
+if (cluster.isPrimary) {
+    const cpuCount = os.cpus().length;
+    console.log(`Primary ${process.pid} running → forking ${cpuCount} workers...`);
+
+    for (let i = 0; i < cpuCount; i++) {
+        cluster.fork();
+    }
+
+    cluster.on("exit", (worker) => {
+        console.log(`Worker ${worker.process.pid} died → restarting...`);
+        cluster.fork();
+    });
+} else {
+    app.listen(HOST, +PORT);
+}
+
+// // Enable built in Graceful Shutdown (optional for production use)
+
+// process.on('SIGINT', async () => {
+//     console.log('SIGINT → shutting down...');
+//     await app.close(2000); // wait up to 2s for requests
+//     process.exit(0);
+// });
+
+// process.on('SIGTERM', async () => {
+//     console.log('SIGTERM → shutting down...');
+//     await app.close(2000);
+//     process.exit(0);
+// });