Answer the question
In order to leave comments, you need to log in
How to find memory leak in node js?
I decided to master the node, wrote a small script. After starting, after a minute, it eats about 1.5GB of RAM.
var mysql = require('mysql');
var request = require('request');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
database : 'items'
});
function pars(){
var startTimer = new Date().getTime();
console.log('Парсим');
request({
url: "https://skinsjar.com/api/v3/load/bots",
json: true,
timeout: 3000,
}, function (error, response, body) {
var elapsed = new Date().getTime() - startTimer;
console.log("Спарсили за: "+elapsed+" мс.");
if (body.items.length > 1){
for (index = 0; index < body.items.length; ++index) {
var price = body.items[index].price; // цена
var name = body.items[index].name; // наименование
var updateItem = "UPDATE ?? SET ?? = ? WHERE ?? = ?"; // шаблон запроса
var inserts = ['items','jar',price,'name',name]; // значения для запроса
connection.query(updateItem, inserts); // обновляем цены
}
console.log("Обновлено "+index+" предметов");
var elapsed = new Date().getTime() - startTimer;
console.log("Время выполнения: "+elapsed+" мс.\n");
} else {
console.log("Сайт недоступен");
}
});
}
setInterval(pars, 4000);
Answer the question
In order to leave comments, you need to log in
Have you ever seen how much data is there? You update line by line, no stream insertion, you generate each request through an asynchronous function, so you get 1000 requests with your own closures, or I’m even afraid to guess how many
Perhaps the calls to the "pars" function "crawl" over each other every four seconds..
I would use setTimeout () and call it in the callback ..on completion of the database update.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question