How to use clusters properly
talhameer opened this issue · 5 comments
talhameer commented
I have created a cluster. But when I run this code. It doesn't work...
import { spawn, worker } from "@stricjs/cluster";
import { Router } from "@stricjs/router";
import { createProduct } from "./controller";
if (worker) {
const app = new Router({
base: "http://localhost:3000",
}).post(
"/",
(req) => {
console.log("url: ", req.url);
return createProduct(req.data);
},
{ body: "json" }
);
Bun.serve(app);
} else spawn(4);
12 | return createProduct(req.data);
13 | },
14 | { body: "json" }
15 | );
16 |
17 | Bun.serve(app);
^
error: Failed to start server. Is port 3000 in use?
at /Volumes/Data/rutal Inc/api-competition/index.ts:17:4
at processTicksAndRejections (:1:2602)
Pls help me what I'm doing wrong.
aquapi commented
@talhameer Try remove the base.
If that doesn't work try fuser -k 3000/tcp
to kill the port and run again.
talhameer commented
@aquapi It doesn't work that way... Because I think the 3000 port is being used by the one of these sub processes.
aquapi commented
@talhameer On my machine all of them can run within a single port.
Can you try it in a Docker environment?
talhameer commented
@aquapi Still no success with docker... Can we have a quick meeting?? I need it to be working so badly... Pls...
aquapi commented
@talhameer Please join the Discord server and ping me
https://discord.com/invite/UeRzaDSM3C