Tuesday, 4 April 2017

NodeJS Cluster on AWS Lambda

Is it possible to use the cluster module in lambda functions? I tried this:

'use strict';
var cluster = require('cluster');  
var http    = require('http');  
var os      = require('os');

var numCPUs = os.cpus().length;
console.log('Number of Cores : ', numCPUs);

exports.test = (event, context, callback) => {
    if (cluster.isMaster) {
        for (var i = 0; i < numCPUs; ++i) {
            cluster.fork();
        }
    } else {
        console.log('child process ');
    }
}

number of cores is always 2, but i never see the child process log.



via Ross Bassett

No comments:

Post a Comment