我們家的Node.js遇到了一些系統上的瓶頸,會導致客戶連結太大量時找不到網頁,做了以下的設定.
還不知道有效否,待測試......
1.先調整了系統網路參數,做法如 http://charleslin74.pixnet.net/blog/post/405007957
2.增加 nodejs socket
require('http').globalAgent.maxSockets = 30000 # 30000也可以設成Infinity
require('https').globalAgent.maxSockets = 30000
3.增加回收機制
node --nouse-idle-notification www.js
4.多進程取代單進程,程式加入
var express = require('express');
...
if (cluster.isMaster) {
// calculate number of proccesses to fork
var num_cpus = require('os').cpus().length;
var num_processes = Math.max(1, num_cpus - 1);
debug('Master starts with %d processes.', num_processes);
for (var i = 0; i < num_processes; i++) {
cluster.fork();
}
// Listen for dying processes
cluster.on('exit', function(worker, code, signal) {
debug('A process(pid=%s) of master died (%s). Restarting...', worker.process.pid, signal || code);
cluster.fork();
});
return;
}
// worker
var app = express();
...
參考文章 http://www.goorockey.com/blog/2014/07/20/high-concurrency-setting-for-nodejs/
留言列表