Answer the question
In order to leave comments, you need to log in
Memory leak when using Sequelize, ORM solution for NodeJS - what to do?
Good afternoon, I recently connected Sequelize following the example from https://github.com/sequelize/express-example. With the only difference that I give all models for export, and do not shove them into one object. Something like:
fs.readdirSync(__dirname+"/../orm").forEach(function(model) {
if (model.substr(-3) == ".js")
module.exports[model] = connections[db].import('../orm/' + model);
}
);
Answer the question
In order to leave comments, you need to log in
There is no leak, the node has a lazy collector that starts working after it takes 1.5GB of RAM. Play around with the keys node --max_old_space_size=256
This is because the model gets into require.cache and even under different names. And most likely you do this several times, not only at startup, and clog the cache, you need to either deliver memory or reduce the volume of the model or load it in parts and then delete it from the cache via delete require.cache[require.resolve('moduleName')] or not to shove into the cache, but into their data structures.
router.get('/test', hutils.authChecker, function(req, res, next) {
Project.findById(1,{ include : [Player]}).then(function(project) {
return Promise.denodeify(async.map)(project.Players, function(player, callback) {
Player.create({
project_id : 1,
name : 'iter_'+Math.floor(Math.random() * 1000000)+Math.floor(Math.random() * 1000000)
}).then(function(gamer) {
callback(null, gamer)
});
});
}).then(function(plrs) {
return Promise.denodeify(async.map)(plrs, function(guy, callback) {
guy.update({name : sqlRequest+'zzzzz'+Math.random()}).then(function(number) {
callback(null, number);
});
});
}).then(function(numbers) {
return Player.findAll({where : {name : {$like : '%zzzzz%'}}});
}).then(function(zets) {
return Promise.denodeify(async.map)(zets, function(zet, callback) {
zet.destroy().then(function(number) {
callback(null, number);
});
});
}).catch(function(err) {
next(err);
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question