FrameworkBenchmarks icon indicating copy to clipboard operation
FrameworkBenchmarks copied to clipboard

Create benchmarks using bun

Open Meir017 opened this issue 3 years ago • 6 comments

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

FYI @Jarred-Sumner

Meir017 avatar Oct 19 '22 09:10 Meir017

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.

muuvmuuv avatar Dec 07 '22 06:12 muuvmuuv

I built one real quick this weekend here: https://github.com/TechEmpower/FrameworkBenchmarks/pull/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.

jtwebman avatar Sep 07 '23 22:09 jtwebman

~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

masfahru avatar Sep 12 '23 15:09 masfahru

Bun does have mutlithreading with the Bun.workers API.

ThatOneCalculator avatar Sep 16 '23 17:09 ThatOneCalculator

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

chlorophant avatar Mar 04 '24 19:03 chlorophant

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 https://github.com/oven-sh/bun/issues/2428 as at least then you are comparing apples to apples.

jtwebman avatar May 06 '24 01:05 jtwebman