* [Bun] use Bun.spawn to increase performance * [Bun] Simple way to get pathname
@@ -10,4 +10,4 @@ COPY ./src .
ENV NODE_ENV=production
-CMD ["bun", "index.ts"]
+CMD ["bun", "spawn.ts"]
@@ -3,8 +3,9 @@ const options: ResponseInit = { headers: { "Server": "Bun" } };
const server = Bun.serve({
port: 8080,
+ reusePort: true,
fetch(req: Request) {
- const { pathname } = new URL(req.url);
+ const pathname = req.url.slice(req.url.indexOf("/", 8));
if (pathname === "/json") {
return Response.json({ message: HELLO_WORLD_STR }, options);
@@ -0,0 +1,9 @@
+import os from "node:os";
+
+const numCPUs = os.cpus().length;
+for (let i = 0; i < numCPUs; i++) {
+ Bun.spawn(["bun", "index.ts"], {
+ stdio: ["inherit", "inherit", "inherit"],
+ env: { ...process.env },
+ });
+}