/
githubmirror
/
socket.io
Обзор
Документация
Войти
/
githubmirror
/
socket.io
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
examples/basic-crud-application/server-postgres-cluster/lib/cluster.js
28 строк
634 B
Damien Arrachequesne
docs(examples): add TODO example with Postgres and Node.js cluster
07 апр 2022, 13:35
Не верифицирован
07 апр 2022, 13:35
be3d7f0
Код
Авторство
О чём код?
import cluster from "cluster"; import { createServer } from "http"; import { setupMaster } from "@socket.io/sticky"; import { cpus } from "os"; if (cluster.isMaster) { console.log(`Master ${process.pid} is running`); const httpServer = createServer(); setupMaster(httpServer, { loadBalancingMethod: "least-connection", }); httpServer.listen(3000); for (let i = 0; i < cpus().length; i++) { cluster.fork(); } cluster.on("exit", (worker) => { console.log(`Worker ${worker.process.pid} died`); cluster.fork(); }); } else { console.log(`Worker ${process.pid} started`); import("./index.js"); }