Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Better multiply CPU support #2265

@AndreasMadsen

Description

@AndreasMadsen

When working with multiply machines (I have never done that so I'm just guessing) no a machine should be able to go online without restrating the cluster.

To support multiply machines you need to know when a CPU is gone offline or added:

//A CPU is added or removed
require('os').on('CPUchange', function (change) {

 //A list of cores 
 change.forEach(function (CPUcore) {
   //If a CPU is appended new workers should be forked 
   if (change.isAppended) {
      cluster.fork();
    } else if (change.isRemoved) {
      //this is bad
    }
  });
});

And know what CPU and/or core the process is running on:

var workers = [require('child_process').fork('worker.js')];
var system = new Setup(); //Custom system from userland

//Disconnect worker
system.on('takeofCPU', function (cpu, callback) {

  //Seach the workers list and disconnect the worker when a CPU ID match is found
  workers.forEach(function (worker) {
   if (worker.cpu.id === cpu.id) {
     worker.disconnect(callback);
   }
  });
});

This is to be used in cluster 2.0 ( see: #2038 ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions