Nodejs在压力测试下崩溃

时间:2014-05-13 14:34:09

标签: node.js testing

我正在尝试模拟1000个websocket连接到测试服务器。我想使用cluster.fork实现它,但使用1000次会耗尽我的内存并使计算机崩溃。异步似乎是解决问题的方法,但是我仍然没有内存。我应该在同时小心我的资源时进行这样的测试吗?如果我使用numCpus而不是500,我只能获得4个连接。

编辑:

if (cluster.isMaster) {
    //This is the master control process
    console.log("Control process running: PID=" + process.pid);
    //Fork workers.
    for (var i = 0; i < 500; i++) {
        worker = cluster.fork();

        //Receive messages from this worker and handle them in the master process.
        worker.on('message', function(msg) {
            console.log('Master ' + process.pid + ' received message from worker ' + msg);
        });
    }
if (cluster.isWorker) {
    console.log('Worker ' + process.pid + ' has started.');

    websocketCreation();//function that creates new WebSockets
    eventHandler();//function that handles on error,close and messagr
}

0 个答案:

没有答案