3
아래의 소켓 서버는 3-4 일 동안 정상적으로 작동하지만 Munin이 지정한 CPU 범위 (160)를 벗어났다는 알림을받은 후 기억이 내게 들리는 것처럼 들리는데, 정확하게는 알지만 찾을 수는 없다.높은 CPU를 사용하는 Socket.io 노드 서버
var io = require('socket.io').listen(80);
var Memcached = require('memcached');
var md5 = require('MD5');
var memcached = new Memcached(['IP']);
var interval_time = 5000;
loglevel = process.argv[2];
if(loglevel == "") loglevel = 1;
io.enable('browser client minification'); // send minified client
io.enable('browser client etag'); // apply etag caching logic based on version number
io.enable('browser client gzip'); // gzip the file
io.sockets.on('connection', function (socket)
{
socket.on('get_notifications', function (data)
{
// verify authorization
if(data.key == 'XXXXXXX')
{
socket.user_id = data.user_id;
setInterval(function()
{
memcached.get(["ntf_" + socket.user_id, "nnt_" + socket.user_id], function(error, mem_result)
{
num_orders = mem_result['ntf_' + socket.user_id];
is_searching = mem_result['nnt_' + socket.user_id];
if(typeof(socket.prev_notification)==='undefined') socket.prev_notification = {};
var notification = socket.prev_notification;
var have_new_notifications = false;
if(is_searching != socket.prev_notification.nnt)
{
have_new_notifications = true;
notification.nnt = is_searching;
}
if(num_orders != socket.prev_notification.ntf)
{
have_new_notifications = true;
notification.ntf = num_orders;
}
if(have_new_notifications)
{
var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
console.log(h+":"+m+":"+s+' - sending notification to ' + data.user_id);
console.log(notification);
socket.emit('notifications', notification);
socket.prev_notification = notification;
}
});
}, interval_time); // interval
}
});
});
아, 나는 '시간 초과'로 변경해보고 며칠 후에 다시 돌아올 것입니다. 감사합니다 :) – Christoffer
이것은 내 문제를 해결 :) – Christoffer