kspchary commited on
Commit
ad21da8
·
verified ·
1 Parent(s): 6c546d3

Upload server.js

Browse files
Files changed (1) hide show
  1. server.js +5 -4
server.js CHANGED
@@ -31,9 +31,10 @@ if (typeof global.File === "undefined") {
31
  */
32
 
33
  if (cluster.isPrimary) {
34
- const numCPUs = os.cpus().length;
 
35
  console.log(`[HighScale] Primary process ${process.pid} is starting...`);
36
- console.log(`[HighScale] Spawning ${numCPUs} worker processes to handle 10k+ concurrency...`);
37
 
38
  // Fork workers for each CPU core
39
  for (let i = 0; i < numCPUs; i++) {
@@ -398,6 +399,6 @@ Rules:
398
 
399
  app.get("/", (req, res) => res.send(`Prachee ai [Worker ${process.pid}] is powering the vibe! 🛸`));
400
 
401
- const PORT = 7860;
402
- app.listen(PORT, () => console.log(`[Worker ${process.pid}] Multi-core node running on port ${PORT}`));
403
  }
 
31
  */
32
 
33
  if (cluster.isPrimary) {
34
+ // Limit workers to prevent OOM in container environments
35
+ const numCPUs = Math.min(os.cpus().length, 3);
36
  console.log(`[HighScale] Primary process ${process.pid} is starting...`);
37
+ console.log(`[HighScale] Spawning ${numCPUs} worker processes...`);
38
 
39
  // Fork workers for each CPU core
40
  for (let i = 0; i < numCPUs; i++) {
 
399
 
400
  app.get("/", (req, res) => res.send(`Prachee ai [Worker ${process.pid}] is powering the vibe! 🛸`));
401
 
402
+ const PORT = process.env.PORT || 7860;
403
+ app.listen(PORT, '0.0.0.0', () => console.log(`[Worker ${process.pid}] Server running on port ${PORT}`));
404
  }