Open Meir017 opened 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.
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.
~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
Bun does have mutlithreading with the Bun.workers
API.
@masfahru Does this example also load balance to each process somehow? If so, does anyone know how that mechanism works?
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.
the deno version - https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/TypeScript/deno/src/main.ts
FYI @Jarred-Sumner