Sunday, 15 January 2012

node.js - Is this leaking memory? -



node.js - Is this leaking memory? -

my code leaking memory. after couple of hours, fills entire memory , crashes. i've simplified code here, able tell if looks leaks? thanks.

var request = require('request').forever(), // per [1] async = require('async'), kue = require('kue'), jobs = kue.createqueue(), pool = { maxsockets: 1 }; function main (job, done) { async.series( [function (callback) { var req = request({url: job.data.url1, pool: pool}, function (err, resp, body) { //stuff... callback(err); }); }, function (callback) { var req = request({url: job.data.url2}, function (err, resp, body) { //stuff... callback(err); }); } ], function (err) { //stuff... done(); } ); } jobs.process('job_name', function (job, done) { //many jobs 'job_name' in queue main (job, done); });

[1] https://groups.google.com/d/msg/nodejs/zi6wndgwwv0/sfm4qkk7odej

i don't think code blame. had same issue using kue, sure wasn't doing wrong made super simple worker this:

var redis = require('redis'), kue = require('kue'), config = require("../../config/local.js"), redisclient = redis.createclient(config.redis), jobs = kue.createqueue({ redis : config.redis }); jobs.process('testjobs', function processjob(job, done, error) { console.log(job.data, error); done(); });

running code made me realize kue 1 leaks. workaround utilize pm2, guy run programme , restart if memory going roof, i'm using json app declaration configure maximum amount of memory allowed before restarting process.

{ "apps" : [ { "name": "test_worker", "script": "test.js", "instances": 1, "max_restarts": 10, "max_memory_restart" : "10m", "ignore_watch": [ "[\\/\\\\]\\./", "node_modules" ], "merge_logs": true, "exec_interpreter": "node", "exec_mode": "fork_mode" } ] }

hope helps.

node.js memory-leaks kue

No comments:

Post a Comment