Questions tagged [node-cluster]

a Node.js module for multi-core network serving.

Cluster is a Node.js module for multi-core network serving.

https://nodejs.org/api/cluster.html

173 questions
0
votes
2 answers

How to properly use database when scaling a NodeJS app?

I am wondering how I would properly use MySQL when I am scaling my Node.JS app using the cluster module. Currently, I've only come up with two solutions: Solution 1: Create a database connection on every "worker". Solution 2: Have the database…
Martin
  • 25
  • 3
0
votes
1 answer

what is the difference between defining variables inside or outside the master code in a Nodejs Cluster?

I am using a cluster and trying to figure out what is the best way to define variables. 1 - var config if (cluster.isMaster) { 2 - var config // master code for (var i = 0; i < numCPUs; i++) { cluster.fork() } …
0
votes
1 answer

How to setup clusters in expressjs 4.x app?

I have an expressjs generated app which is configured with socket io and I would like to implement nodejs clusters in it. The problem is that in Express 4.x the server listening configuration is in the bin/www file and no longer in app.js file. Also…
Lolpez
  • 849
  • 8
  • 17
0
votes
1 answer

What happens to the cluster master when all Node workers die?

So I have been trying to understand how Node cluster works and I have this code: const cluster = require('cluster') const os = require('os') const express = require('express') const app = express() let cpus // Check to see if the master process is…
Mike Mulligan
  • 188
  • 11
0
votes
1 answer

NodeJS clustering, is it a good idea to use the master process for a separate job?

I'm trying to create an auction application and I'm thinking of using node-schedule to determine when each auction end. The idea is to run the auction countdown on the master process while leaving the api stuff to the workers. This way, even if the…
Combustible Pizza
  • 315
  • 1
  • 2
  • 8
0
votes
1 answer

Moongose not connecting to DB in a cluster node

I have a setup with a clustered nodejs app (1 Master and 4 Workers). The master instantiate the workers and create a bunch of tasks that they can grab. Each worker initiate a DB connection like this : import Database from './db'; //Worker class…
HRK44
  • 2,382
  • 2
  • 13
  • 30
0
votes
0 answers

Redirecting between Express servers

I'm making an io game. The app is divided into main thread and worker threads. In every thread is an Express server running and a Socket.io server binded to it. I want to be able to switch between these servers, so the thread does all the work for…
0
votes
1 answer

Sum up values from workers NodeJS

I have master and workers that calculate something in parallel. How to sum up their results? After each worker has done his job, he kill himself and 'res' variable has no value, so it's impossible to accumulate it to any variable. if…
user7836085
0
votes
0 answers

Node.js Cluster: Get all connections

I need to figure out the count of all active connections for an entire node.js cluster. I've implemented a dirty solution using IPC where the master process keeps track of responses from each worker and then returns the sum. Isn't there a cleaner…
Anshuul Kai
  • 3,876
  • 2
  • 27
  • 48
0
votes
1 answer

How to view which cluster worker responded nodejs?

How can someone view which cluster worker responds each time a request is made to the server, in the console.log? I am using express.
prieston
  • 1,426
  • 2
  • 18
  • 39
0
votes
0 answers

Cluster is failing on windows

I was using PM2 to start my web application in cluster mode when I realized that it wasn't working on windows, I tried to track the issue and realized that all kinds of clustering are failing on my system. When I try to start any clustered node…
Esam Bustaty
  • 346
  • 1
  • 4
  • 13
0
votes
1 answer

Nodejs events captured in any cluster process sent from cluster creating file

I am stuck here due to a simple event related issue. Here is the issue: I have created a cluster using cluster.js and forked server.js from cluster.js. I have put a timer from cluster.js and after every 1 min I am triggering an event…
Gary
  • 2,293
  • 2
  • 25
  • 47
0
votes
0 answers

Node's Cluster Fork

I don't understand how clusters work in Node. The snippet below is example code from Node's docs. const cluster = require('cluster'); const http = require('http'); const numCPUs = require('os').cpus().length; if (cluster.isMaster) { …
Lucien
  • 776
  • 3
  • 12
  • 40
0
votes
1 answer

NodeJS clusters assign server port from config file

Since the server configuration is stored in an XML file before assigning the port to app for listening I have to read the XML file, convert the XML string output to JSON for readability. I also using node clusters to make node performing better.…
Soojoo
  • 2,146
  • 1
  • 30
  • 56
0
votes
1 answer

Node cluster not listening, cluster exits and not respond

This problem i got on my machine only. I tried my code on other machines it works perfectly, I didn't got any solution because there is no code level problem, may be its OS problem or may be Nodejs version problem, I don't know. Operating Syatem:…
Gaurav Kumar Singh
  • 1,550
  • 3
  • 11
  • 31