Sunday 15 January 2012

javascript - Does node.js memory usage increase as the number of simultaneous requests increase, or is this a leak? -



javascript - Does node.js memory usage increase as the number of simultaneous requests increase, or is this a leak? -

i have next node.js code running:

var http = require('http'); http.createserver(function(req,res){ res.writehead(200,{'content-type': 'text/plain'}); res.write("hello"); res.end(); }).listen(8888);

when start server (by typing node myfile.js), node process using 9mb of memory.

then created next webpage open in several tabs in web browser, simultaneously create requests node:

<html> <head> <script> var ajax = {}; var questions = []; var questionsresponses = []; ajax.x = function() { if (typeof xmlhttprequest !== 'undefined') { homecoming new xmlhttprequest(); } var versions = [ "msxml2.xmlhttp.5.0", "msxml2.xmlhttp.4.0", "msxml2.xmlhttp.3.0", "msxml2.xmlhttp.2.0", "microsoft.xmlhttp" ]; var xhr; (var = 0; < versions.length; i++) { seek { xhr = new activexobject(versions[i]); break; } grab (e) {} } homecoming xhr; }; ajax.send = function(url, callback, method, data, async) { var x = ajax.x(); x.open(method, url, async); x.onreadystatechange = function() { if (x.readystate == 4) { if (x.status == 200) { callback(x.responsetext) } else { //todo } } }; if (method == 'post') { x.setrequestheader('content-type', 'application/x-www-form-urlencoded'); } x.send(data) }; ajax.get = function(url, data, callback, async) { var query = []; (var key in data) { query.push(encodeuricomponent(key) + '=' + encodeuricomponent(data[key])); } ajax.send(url + '?' + query.join('&'), callback, 'get', null, async) }; ajax.post = function(url, data, callback, async) { var query = []; (var key in data) { query.push(encodeuricomponent(key) + '=' + encodeuricomponent(data[key])); } ajax.send(url, callback, 'post', query.join('&'), async) }; var count = 0; function sayhello(){ ajax.get("http://localhost:8888", {}, sayhello, true); var heading = document.getelementbyid("c"); while (heading.firstchild) { heading.removechild(heading.firstchild); } var counttext = document.createtextnode(""+count++); heading.appendchild(counttext); } </script> </head> <body> <h1 id="c"></h1> <script> sayhello();</script> </body> </html>

the memory node using 46.2 mb. increases. every 1 time in while there jump, , continues increase. normal behavior of node when getting many simultaneous requests, or leak ?

edit: seems stable @ 46.4 mb. don't know whether stable because number of requests create limited (since i'm opening multiple tabs in web browser), limitation of laptop. xd

edit: memory increment seems happen if create 1 request @ time (ie. opening 1 tab in web browser). also, after closing windows, memory used doesn't decrease (it remains @ 46.4 mb).

of course of study there proportionality between number of requests , memory usage: every request needs objects (ex.: req, res, ...) handled , every object takes memory. in nodejs applications noted increasing of requests memory increases falls downwards under action of google v8 engine garbage collector efficient. anyway, memory leaks behind corner sure it's not possible speak memory leak memory usage around 50 mb 1 speaking about.

javascript node.js memory-leaks

No comments:

Post a Comment