Clustering
Run multiple instances to distribute workloads
Cluster can be used to run multiple instances that can distribute workloads among their application threads. When process isolation is not needed, use Worker instead, which allows running multiple application threads within a single instance.
Install the cluster module by:
bun add @stricjs/clusterHere's an example of serving a web server with 4 threads.
import { Router, macro } from '@stricjs/router';
import { spawn, worker } from '@stricjs/cluster';
if (worker) {
const app = new Router().get('/', macro(
() => new Response('Hi')
));
Bun.serve(app);
} else spawn(4);Last updated
Was this helpful?