P
P
Pavel Chuev2015-11-15 20:41:02
JavaScript
Pavel Chuev, 2015-11-15 20:41:02

Fetch eats a lot of RAM. How to fix?

var humanize = require('humanize');
var request  = require('request');

function fetch(url, c) {
  request(url, function(err, resp, body) {
        if (err) {
            c(err);
            return;
        }
        c(err, resp, body)
    });
}
function callback(err, resp, body) {
    var memory = process.memoryUsage();
    console.log("Memory usage: " + humanize.filesize(memory.heapUsed) + " / " + humanize.filesize(memory.heapTotal));
    fetch('тут_url_запроса', callback)
}
function Number() {
    fetch('тут_url_запроса', callback);
}
setInterval(Number, 350)

Here is almost the entire code. After reading the forums and other sites with information, I did not find anything ..
Ps I found the launch parameters on Habré: node --nouse-idle-notification --expose-gc server.js
they do not help.
With each request, the RAM grows up to >100 and the process is killed automatically.
So how to get rid of such an increase in RAM? After all, ordinary html requests require hard RAM.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Koryukov, 2015-11-16
@MadridianFox

Your fetch calls the callback passed to it, and the callback calls fetch again, and so on in a circle.

P
pomeo, 2015-11-16
@pomeo

You don't need those keys, and node --max_old_space_size=128 server.js
128 is megabytes. Without keys, a node usually takes up 1.5GB of memory

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question