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

Create benchmarks using bun #7646

Open
Meir017 opened this issue Oct 19, 2022 · 6 comments
Open

Create benchmarks using bun #7646

Meir017 opened this issue Oct 19, 2022 · 6 comments

Comments

@Meir017
Copy link

Meir017 commented Oct 19, 2022

the deno version - https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/TypeScript/deno/src/main.ts

FYI @Jarred-Sumner

@muuvmuuv
Copy link

muuvmuuv commented Dec 7, 2022

Yes, would love other JavaScript and TypeScript engines compared here: deno and bun. Also zig (which bun is written in) as a language is also missing.

@jtwebman
Copy link
Contributor

jtwebman commented Sep 7, 2023

I built one real quick this weekend here: #8407 Once Bun 1.0 is released will update it to that. Would love any feedback as I don't know if I fully optimized it or not.

@masfahru
Copy link
Contributor

masfahru commented Sep 12, 2023

I think we should wait until the implementation of node:cluster module is done

Edit:
We can imitate the behavior of the node:cluster in Bun to spawn as many server instances as the number of CPU cores, using this script.

spawn.ts

import os from 'node:os';

const numCPUs = os.availableParallelism();

for (let i = 0; i < numCPUs; i++) {
  Bun.spawn(['bun', 'src/index.ts'], {
    stdio: ['inherit', 'inherit', 'inherit'],
    env: { ...process.env },
  });
}

index.ts

Bun.serve({
  port: 8080,
  reusePort: true, // allow Bun server instances to use same port 
  fetch(req: Request) {
    // ...

An example using Elysia.js

import { Elysia } from 'elysia';

const app = new Elysia({
  serve: {
    reusePort: true,
  },
})
  .get('/', () => 'Hello Elysia')
  .listen(8080);

console.log(
  `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`
);

run bun spawn.ts

@ThatOneCalculator
Copy link

Bun does have mutlithreading with the Bun.workers API.

@chlorophant
Copy link

chlorophant commented Mar 4, 2024

@masfahru Does this example also load balance to each process somehow? If so, does anyone know how that mechanism works?

@jtwebman
Copy link
Contributor

jtwebman commented May 6, 2024

It doesn't. Node wrote their own into their stuff https://nodejs.org/api/cluster.html Bun.js doesn't support that yet but you probably could add a simple one oven-sh/bun#2428 as at least then you are comparing apples to apples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants