Closed
Description
Hi,
We are using 0.9.6,
We've been noticing memory usage increasing until the server stops responding.
It usually would take a few days until this happened but now we increasing usage (about 220 peers) , the server stops responding in less than one day.
Should we be destroying some objects, releasing some connection? Anything we are not doing that we should do to stop this?
Our client setup:
var socket;
var subs = new pc.util.OrderedMap();
function addSubscription(subtopic, callback) {
if(!PCAUser.loggedIn) return;
subs.put(subtopic, callback);
if(!socket) {
initSockeIO();
} else {
socket.json.send({
command : "subscribe",
subscriptions: [subtopic]
});
}
}
function initSockeIO() {
socket = io.connect(liveUpdateConfig.host,
{port: liveUpdateConfig.port, rememberTransport: false});
socket.on('message', function(obj) {
if (obj.subtopic) {
var key = obj.subtopic;
if (subs.get(key)) {
// execute callback
window[subs.get(key)](obj); // FIXME bad approach
}
}
});
socket.on('connect', function subscribe(obj) {
socket.json.send({
command : "subscribe",
subscriptions : subs.keys()
});
});
socket.on('disconnect', function(obj) {
setTimeout(function() {
socket = io.connect(liveUpdateConfig.host,
{port: liveUpdateConfig.port, rememberTransport: false});
}, 1000);
});
}
jQuery(document).unload(function() {
if(socket) {
socket.emit('disconnect');
}
});
Our server setup:
//--------- Socket.IO server ---------
var socketio = io.listen(server, {
transports: ['websocket','flashsocket','htmlfile','jsonp-polling']
});
socketio.sockets.on('connection', function(client) {
stats.peersCount ++;
var msg = "Client connected: " + client.id + ", active peers count: " + stats.peersCount;
logger.info(msg);
socketio.sockets.send(msg);
client.on('message', function(message) {
var decodedMessage = util.inspect(message, true, 3);
logger.info("\n\Client " + client.id + " Message received : " + decodedMessage);
if( decodedMessage.indexOf('monitor') > -1) {
logger.info('monitor enabled');
if(!subscriptions[monitor_subscription]) {
subscriptions[monitor_subscription] = [client];
} else {
subscriptions[monitor_subscription].push(client);
}
logger.info("Client " + client.id + " added as monitor");
client.json.send({ subscriptions : [monitor_subscription] });
} else
if (typeof message.command != undefined) {
try {
switch (message.command) {
case "subscribe":
var incomingSubscriptions = message.subscriptions;
//if the subscriptions are in a string, split them into an array
if(message.subscriptions.replace) {
incomingSubscriptions = message.subscriptions.replace('[','').replace(']','').replace(/[\"\s]/g, '').split(',');
}
for (var i = 0; i < incomingSubscriptions.length; i++) {
var subtopic = incomingSubscriptions[i];
if (!subscriptions[subtopic]) {
subscriptions[subtopic] = [client];
} else if(subscriptions[subtopic].indexOf(client) < 0) {
subscriptions[subtopic].push(client);
}
}
logger.info("Client " + client.id + " subscribed");
client.json.send({ subscriptions : message.subscriptions });
break;
default:
logger.info("Undefined message: " + decodedMessage);
}
} catch (e) {
logger.error('Error while handling message ' + decodedMessage + ", " + e.message);
}
}
});
client.on('disconnect', function() {
stats.peersCount --;
var msg = "Client " + client.id + " disconnected, active peers count: " + stats.peersCount;
socketio.sockets.send(msg);
logger.debug(msg);
for (var subtopic in subscriptions) {
if (subscriptions[subtopic].length > 0) {
subscriptions[subtopic] = subscriptions[subtopic].filter(function(element) {
return element.id != client.id
});
}
}
});
});
Thanks,
Barbara
Metadata
Metadata
Assignees
Labels
No labels