TechEmpower / FrameworkBenchmarks

Source for the TechEmpower Framework Benchmarks project
https://www.techempower.com/benchmarks/
Other
7.52k stars 1.93k forks source link

Create benchmarks using bun #7646

Open Meir017 opened 1 year ago

Meir017 commented 1 year ago

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

FYI @Jarred-Sumner

muuvmuuv commented 1 year ago

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 commented 10 months ago

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.

masfahru commented 10 months ago

~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 commented 10 months ago

Bun does have mutlithreading with the Bun.workers API.

chlorophant commented 4 months ago

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

jtwebman commented 2 months ago

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.