javascript - Node.JS memory increasing issue -


i have done small program work crone job , hosted it, when make call www.myurl.com:3030/start, script start , every 10 seconds api call happen until set send time met. end time can in 1 or 2 hour since script started, how works when 1 time called. can called again till 100 times, issue is. memory increasing nothing,

i tried running twice, memory ran in 90 mb. have question isnt there grabage collection done in node.js ? have tried deploying forever , pm2 both still same.

this code, simple code.

var express = require('express'); var path = require('path'); var app = express(); var router = express.router(); var bodyparser = require('body-parser'); var moment = require('moment'); var http = require('http');  //app.use( bodyparser.json() );       // support json-encoded bodies  app.use(bodyparser.urlencoded({     // support url-encoded bodies     extended: true }));  app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade');  app.use(router); app.use(express.static(path.join(__dirname, 'public')));  router.all('/', function (req, res, next) {     console.log('someone made request');     console.log(req.body);     next(); });  router.get('/', function (req, res) {     res.render('index'); });  router.post('/secret', function (req, res) {     console.log('post request!');     var utcnow = moment.utc();     console.log('start at:' + utcnow.format("yyyy-mm-dd hh:mm:ss"));      function callbackurl(url, data){         console.log('callback url request at: ' + moment.utc().format("yyyy-mm-dd hh:mm:ss"));         var request = require('request');          request.post(             url,             {form: {data: data}},             function (error, response, body) {                 if (!error && response.statuscode == 200) {                     console.log(body)                 }             }         );      }      var startat = req.body.startat;     var callback = req.body.callback;     var oldcallback = callback;     var endat = moment(req.body.endat+" +0000", "yyyy-mm-dd hh:mm:ss z"); //req format:- 2015-05-15 11:23:50     var data = req.body.data;     var  = moment.utc().format("yyyy-mm-dd hh:mm:ss");     var delay = (moment(now,"yyyy-mm-dd hh:mm:ss").diff(moment(startat,"yyyy-mm-dd hh:mm:ss")) / 1000);     console.log(startat + ' - ' + + ' = ' + delay);       if (callback == "" || endat == "" || data == ""){         console.log('params cannot empty: ' +  json.stringify(req.body));         res.end('params cannot empty: ' + json.stringify(req.body));     }      if (utcnow.diff(endat, 's') >= 0){         console.log('param "endat" invalid: ' +  json.stringify(req.body));         res.end('param "endat" invalid: ' + json.stringify(req.body));     }      var jsonobject = json.parse(data); //to json object of string       var callbackurl1 = 'http://qa.website.com/index.php/api/default/test/id/1';     var callbackurl2 = 'http://qa.website.com/index.php/api/default/test/id/2';      var nowcount = 0;      var ctask = setinterval(function() {         nowcount++;         var utcdate = moment.utc();          console.log('crn tick time: ' + moment.utc().format("yyyy-mm-dd hh:mm:ss"));          var _mtime = utcdate.clone();         _mtime.subtract(callback, 's');         console.log('callback time: ' + callback * 1000);          var tmpendat = utcdate.format("yyyy-mm-dd hh:mm:ss");         var tmpstartat = _mtime.format('yyyy-mm-dd hh:mm:ss')          if (nowcount == 1) {             callback = parseint(callback) - delay;             tmpstartat = startat;             console.log('1st time ' + callback);         }         else {             callback = oldcallback;             console.log('not 1st time ' + callback);         }         jsonobject.startat = tmpstartat;         jsonobject.endat = tmpendat;         data = json.stringify(jsonobject);          callbackurl(callbackurl1, data);          if (utcdate.diff(endat, 's') >= 0) {             clearinterval(ctask);             console.log('stopped at: ' + moment.utc().format("yyyy-mm-dd hh:mm:ss"));             console.log('now count: ' + nowcount);             callbackurl(callbackurl2, data);         }     }, callback * 1000);      console.log("post body: %j", req.body);     res.end('body: ' + json.stringify(req.body));  });  app.listen(3030); module.exports = app; 


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -