Stric
  • Basic
    • Intro
    • Routing
    • Serving files
    • Sending HTML
    • Quick response
    • CORS
    • Server-sent events
    • Clustering
  • Advance
    • How it works?
    • More
Powered by GitBook
On this page

Was this helpful?

  1. Basic

Clustering

Run multiple instances to distribute workloads

Last updated 1 year ago

Was this helpful?

Cluster can be used to run multiple instances that can distribute workloads among their application threads. When process isolation is not needed, use instead, which allows running multiple application threads within a single instance.

Install the cluster module by:

bun add @stricjs/cluster

Here'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);
Worker