AWS Lambda和NodeJS群集

时间:2017-04-17 15:56:58

标签: node.js amazon-web-services lambda aws-lambda

我写了这个简短的例子来测试AWS lambda中的集群。谁能告诉我哪里出错了?核心数返回2,但消息永远不会传递。

'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);
}

0 个答案:

没有答案