Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bun dont work with cluster #14727

Open
imezx opened this issue Oct 22, 2024 · 3 comments
Open

Bun dont work with cluster #14727

imezx opened this issue Oct 22, 2024 · 3 comments
Labels
bug Something isn't working needs triage

Comments

@imezx
Copy link

imezx commented Oct 22, 2024

What version of Bun is running?

1.1.32-canary.21+ae8de1926

What platform is your computer?

Microsoft Windows NT 10.0.26100.0 x64

What steps can reproduce the bug?

(app.js)

import { Hono } from 'hono';
import cluster from 'node:cluster';
import os from 'node:os';
import dotenv from 'dotenv';
dotenv.config();

const numCPUs = os.cpus().length;
const MaxCPUs = 8;
const port = process.env.PORT;

if (cluster.isPrimary) {
    console.log(`Primary ${process.pid} is running`);
    for (let i = 0; i < Math.min(Math.max(numCPUs, 1), MaxCPUs); i++) cluster.fork();
    cluster.on('exit', (_) => cluster.fork());
    process.on('SIGINT', () => {
        process.exit(0);
    });
} else if (cluster.isWorker) {
    const app = new Hono();
    console.log(cluster.worker.id, process.pid);
    app.get('/id', (c) => {
        // console.log(cluster.worker.id);
        return c.text(cluster.worker.id);
    });
    Bun.serve({ fetch: app.fetch, port, reusePort: true, development: false });
    console.log(`Server running on http://127.0.0.1:${port}`);
}

(index.js)

Bun.spawn(["bun", "./app.js"], {
    stdio: ["inherit", "inherit", "inherit"],
    env: {
        ...process.env
    },
});

run: bun index.js

What is the expected behavior?

i never had this worked since v1.1.2 before (i start using bun at v1.1.2) but it works if run with nodejs.

What do you see instead?

Image
Image
Image
Image

this made bun is not faster than nodejs (bun is slower 1-5%) due the clusters dont work

Additional information

No response

@imezx imezx added bug Something isn't working needs triage labels Oct 22, 2024
@imezx
Copy link
Author

imezx commented Oct 22, 2024

i have also tried using native bun serve (from: here) but still the same thing

@imezx
Copy link
Author

imezx commented Oct 22, 2024

my old issue

@imezx
Copy link
Author

imezx commented Oct 22, 2024

Image
(another test)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant