javascript - Memory leaks in node.js with concurrent sse connections -


i'm developing high-load testing tool, using eventsource npm library generate concurrent sse connections.

i use centos on digitalocean 512mb , 1cpu.

take @ code:

var http = require("http"),  eventsource = require('eventsource'), opensockets = 0; http.globalagent.maxsockets = 70000;  console.log(process.memoryusage() )  begintest();  function begintest (options) {   (var = 0; < 50000; i++) {     settimeout(formposter(i),0);   } } function formposter (i) {   var url = "http://remoteserver.com/examples/events/connect.sse",       es = new eventsource(url);    es.onmessage = function(e) {    };    es.onerror = function(e) {     console.log(e);   };   es.onopen = function(e) {     opensockets++;      if (opensockets == 1 ) {       console.log(process.memoryusage() );       process.exit(code=0);        }  }; }  

the problem code huge memory leak - first console.log statement outputs

{ rss: 8925184, heaptotal: 5066496, heapused: 2113192 } 

whereas second 1 (after first connected ) outputs { rss: 373219328, heaptotal: 296538752, heapused: 286450700 } herewith remoteserver has around 1500 connection local machine.

what reasons can cause such memory leaks?

you don't have memory leak - instantiating lot of objects @ same time , garbage collection event has not yet occurred.

the line settimeout(formposter(i),0) isn't doing think - because you're formposter, rather passing reference, timeout has no effect. calling formposter 50,000 times immediately.

in fact, if did pass function settimeout deferred execution this:

settimeout(function() {   formposter(i) }) 

then still see same effect, deferred later execution of event loop.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -