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
699
votes
17 answers

Node.js on multi-core machines

Node.js looks interesting, BUT I must miss something - isn't Node.js tuned only to run on a single process and thread? Then how does it scale for multi-core CPUs and multi-CPU servers? After all, it is all great to make fast as possible…
zaharpopov
  • 16,882
  • 23
  • 75
  • 93
60
votes
8 answers

Puppeteer - Protocol error (Page.navigate): Target closed

As you can see with the sample code below, I'm using Puppeteer with a cluster of workers in Node to run multiple requests of websites screenshots by a given URL: const cluster = require('cluster'); const express = require('express'); const…
23
votes
6 answers

how to keep variables that share all node processes in node cluster?

It seems like all the node woker processes are working as if it is executing a new copy of the same application. But would like to keep some variables that are shared by all node workers (child processes) in node cluster. Is there a simple way to do…
lahiru madhumal
  • 1,185
  • 2
  • 12
  • 30
14
votes
1 answer

How to use nodeJS cluster with mySQL pool cluster?

Quick question If I make a node cluster application with 4 workers (4 instances of my application), should I use mySQL pool or mysql pool cluster? If I use pool it will create one pool for each application but If I use pool cluster it will create 4…
prieston
  • 1,426
  • 2
  • 18
  • 39
12
votes
3 answers

How to run Node Cluster on windows?

Anyone know how to run Node Cluster on windows? I haven't been able to find any articles on the web and cannot seem to solve this problem: events.js:160 throw er; // Unhandled 'error' event ^ Error: write ENOTSUP at…
wayofthefuture
  • 8,339
  • 7
  • 36
  • 53
11
votes
3 answers

How can I Handle Socket.IO rooms with cluster?

I have a server working with cluster and to make that work with socke.IO I am using sticky-session, but I have a problem with my rooms (I don't know if the way I did is the best option): The cluster is instantiating processes and each process has a…
Tiago Fabre
  • 739
  • 5
  • 18
10
votes
1 answer

How does node.js cluster module allow multiple child process to listen on the same port?

Using Node.JS and cluster module. I am trying to understand how multiple forked child processes can listen on the same port. For example, using cluster module we can do this: const port = 443; ... if (cluster.isMaster) { for(let i = 0; i <…
Ryan Griggs
  • 2,457
  • 2
  • 35
  • 58
7
votes
3 answers

Nodejs Clustering with Sticky-Session

const cluster = require('cluster'); const http = require('http'); const numCPUs = require('os').cpus().length; if (cluster.isMaster) { console.log(`Master ${process.pid} is running`); // Fork workers. for (let i = 0; i < numCPUs; i++) { …
codefreaK
  • 3,584
  • 5
  • 34
  • 65
7
votes
1 answer

Node Cluster: How to assign separate server/port to each worker?

I understand that I can use Nodes cluster module in order to create several workers all serving the same socket connection (example from docs): var cluster = require('cluster'); var http = require('http'); var numCPUs =…
csvan
  • 8,782
  • 12
  • 48
  • 91
7
votes
2 answers

Debugging stray uncaught exceptions (ECONNRESET) in a node cluster

In my node.js app which uses the cluster module, I'm intermittently seeing errors like this: events.js:71 throw er; // Unhandled 'error' event ^ Error: read ECONNRESET at errnoException (net.js:863:11) at TCP.onread…
Matt Zukowski
  • 4,469
  • 4
  • 37
  • 38
6
votes
2 answers

Scaling websockets/ws with multiple server instances

I am using websockets/ws on single machine. Its working fine. I want to scale it horizontally on multi-core and on multiple instances. For mutli-core I tried with pm2 and it seems working great. First Q: Is this the best approach or suitable…
Gagan
  • 1,267
  • 3
  • 18
  • 28
6
votes
1 answer

100% CPU usage using clusters and mariaSQL, when cluster is exit and restarted

On my Node.JS app I'm using clusters to utilize my multi-core CPU. I'm using the node's mariasql library to communicate with my database. Since the node-mariasql library does not support pooling, I am using the third party - generic-pool to maintain…
Abijeet Patro
  • 2,842
  • 4
  • 37
  • 64
6
votes
1 answer

node cluster with socket.io and expressjs

Here's my server code: I'm trying to use cluster with socket.io and expressjs. I'm testing this on my quad core desktop. var cluster = require('cluster') var numCPUs = require('os').cpus().length if (cluster.isMaster) { // Fork workers. for…
Harry
  • 52,711
  • 71
  • 177
  • 261
5
votes
4 answers

node cluster.isPrimary is undefined

Node says that cluster.isMaster is deprecated and we should use cluster.isPrimary. But, while isMaster is returning me true without problem, I getting undefined when I try cluster.isPrimary: const cluster =…
5
votes
1 answer

Node.js Cluster Shared Cache

I'm using node-cache to create a local cache, however, the problem I have is that when using the application with PM2 which creates an application cluster the cache is created multiple times, one for each process - this isn't too much of a problem…
Tam2
  • 323
  • 1
  • 5
  • 16
1
2 3
11 12