Skip to content

How to use this library with node cluster? #24

@xfg

Description

@xfg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions