Node.js - Large number of post request to another server causes memory leak

838 views Asked by At

I have a node app that makes large number of request to another server using restify.

As the number of requests increases,memory keeps on growing and ultimately the app crashes.

Below is the snippet of my code.

var restify = require('restify');
var client = restify.createStringClient({
    url: "https://api-3t.sandbox.paypal.com/nvp"
});

function makeRequest(cb) {
    counter++;
    client.post({
            headers: null
        }, null, function(err, req, res, data) {
            if(err)
            {
                cb(err, req, res, data);
            }
            else
            {
                cb(null, req, res, data);
            } 
    });
}

function makeRequestCb(error,request,response,data){
    counter++;
    console.log("result",counter);
}

setInterval(function(){
        makeRequest(makeRequestCb)
}, 1000);

On checking the heap snapshot in chrome I found that 'buffer' is taking up most of the space.

I have also tries using 'request' module instead of 'restify' What am I doing wrong here. What is holding up most of the space?

I have checked this post as well. But in my case the memory usage just keeps on increasing.

Please help.

0

There are 0 answers