my company is struggling with some issues. The node.exe is taking up too much memory and CPU.
The server looks like this:
var userList = [];
/* NODE.JS */
var server = require('http').createServer(function (req, res) {
res.writeHead(200);
res.end('ok');
}).listen((process.env.PORT || 88));
/* SOCKET.IO */
//var io = require('socket.io')(server);
var io = require('socket.io')(server);
io.on('connection', function (socket) {
socket.on('connectUser', function (user) {
if (!isAuthenticated(user.user, user.pass)) {
socket.disconnect(socket.conn.id);
} else {
//Session des Users
user.session = socket.conn.id;
//if (userList.indexOf(user)== -1)
userList.push(user);
io.emit('userOnline', {onlineUser: userList});
}
});
socket.on('sendMessageToUser', function (sendObj) {
if(sendObj && sendObj.to) {
var userArr = userList.filter(function(val, index, arr) {
if(sendObj.to.indexOf(val.id) > -1)
return val;
});
userArr.forEach(function(user) {
socket.to(user.session).emit('getMessageFromUser', sendObj);
});
}
});
socket.on('disconnect', function () {
userList = userList.filter(function(val, index, arr) {
if(val.session !== socket.conn.id)
return val;
});
io.emit('userOnline', {onlineUser: userList});
});
});
function isAuthenticated(user, pass) {
return true;
}
When a user connects (each page visit) will be a connect to the server. A userList
will be filled with information about that user. After leaving the page or refresh the user is removed from that object.
The server also hosts another node.js application. After starting my script the other application is rising in memory and CPU also!
Can anyone confirm that this is a bug? Or do I have to treat two applications different?
My server looks like this: iisnode (v 0.2.18.0) node (v 0.12.4) npm (v 2.10.1) socket.io (v 1.3.5)
I know that most of them are really outdated! I hadn't had time to test current versions under iisnode.