- the raw native tcp server I used a client test code to concurrent long connect the server, and do nothing。 After 5w conncetions I shut down the client.js, but the server side will have about 100M memory don't release.
the server code :
var net = require('net');
var server = net.createServer(function(client) {
console.log('server connected');
client.on('data',function(){});
client.on('end',function(){console.log('end');});
});
server.listen(8124, function() {
console.log('server bound');
});
the client code:
var net = require('net');
var host = '192.168.0.110'
// var host = "localhost"
, port = 8124
for(var i=0; i < 50000; i++){
var client = net.connect({host: host, port: port},
function(i){
return function() { //'connect' listener
var num = i;
console.log('client connected ' + num);
}}(i)
);
client.on('end',function(){
console.log('end');
client.end()
})
}
the client is on another machine
2, long loop
var a = b = c = d = [];
console.log((process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2), 'Mb');
for(i=0;i<50000;i++){
a.push(new Date());
b.push(new Date());
c.push(new Date());
d.push(new Date());
}
console.log((process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2), 'Mb');
a = null;
b = null;
c = null;
d = null;
console.log('null');
console.log((process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2), 'Mb');
console.log((process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2), 'Mb');
setInterval(function(){
console.log((process.memoryUsage().heapUsed / 1024 / 1024).toFixed(2), 'Mb');
},5000);
I set the variable to null but the memory does not release. somebody tell me to use process.nextTick to prevent long loop but it still doesn't work.