Created
February 17, 2022 21:50
-
-
Save cnorthwood/9026d224988a486035a7081fbdc032f4 to your computer and use it in GitHub Desktop.
using cluster module for multiple CPUs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cluster from "cluster"; | |
import { cpus } from "os"; | |
import app from "./app"; | |
const numWorkers = cpus().length; | |
if (cluster.isPrimary) { | |
for (let i = 0; i < numWorkers; i++) { | |
cluster.fork(); | |
} | |
} else { | |
app.listen(8443); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment