I wrote this short example to test clustering in AWS lambda. Can someone tell me where I went wrong? The number of cores returns 2, but the message is never passed.
'use strict';
var cluster = require('cluster');
var http = require('http');
var os = require('os');
var numCPUs = os.cpus().length;
exports.test = (event, context, callback) => {
console.log('Number of Cores : ', numCPUs);
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; ++i) {
cluster.fork();
}
for (const id in cluster.workers) {
cluster.workers[id].on('message', messageHandler);
}
} else {
process.send('running');
}
};
function messageHandler(msg) {
console.log(msg);
}
via Ross Bassett
No comments:
Post a Comment