Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this library with node cluster? #24

Open
xfg opened this issue Mar 12, 2016 · 2 comments
Open

How to use this library with node cluster? #24

xfg opened this issue Mar 12, 2016 · 2 comments

Comments

@xfg
Copy link

xfg commented Mar 12, 2016

Hi. I have typical node cluster.

var cluster = require('cluster');
var numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
  for (var i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on('exit', (worker, code, signal) => {
    console.log('worker ' + worker.process.pid + ' died');
  });
} else {
  require('./worker.js');
}

Now I want to use mysql-live-select within worker.js but I want to it was connected to mysql only once and this connection could be shared between workers.

Right now I am wrote this within worker.js

//worker.js
var LiveMysql = require('mysql-live-select');
var settings = {
  host        : 'localhost',
  user        : 'root',
  password    : '',
  database    : 'fc',
  //serverId    : 1,
  minInterval : 200
};
var liveMysql = new LiveMysql(settings);

but this does not work and I get an error: Error: ER_CON_COUNT_ERROR: Too many connections

How to fix? Thanks.

@numtel
Copy link
Owner

numtel commented Mar 13, 2016

Why do you have the serverId setting commented out? Each worker needs to have a unique value for serverId.

@xfg
Copy link
Author

xfg commented Mar 13, 2016

Because initially I wanted to do so that the connection to mysql was established only once from parent process and propagated to all workers who should be used this connection.

But during my experiments I noticed that the serverId does not affect anything. If I comment out the serverId then all workers still normal receive the updates from mysql. Do you know anything about this behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants