mongojs
mongojs copied to clipboard
mongojs stop processing further find requests after 2 mins
Hi I am using mongodb version 3.0.7 and v2.4.0 of mongojs.
// Fetch from database
db.products.find($query).sort(options.sort).skip(options.skip).limit(options.limit, function(err, docs){
if(err){
res.status(500).end();
}
else if(_.isEmpty(docs)){
res.status(204).end();
}
else{
res.json(docs);
}
});
Above is the simplest code for fetch some data from database. It works fine for 2 mins but after that, it just doesn't return the docs. Hence http request times out with status code 502 (Bad Gateway).
I am sure their might be some sort of memory leak in here but strangely other findOne queries are working fine even after this code breaks. Console doesn't show any error when this happens.
Any idea on this one guys?
Hi, we have the same problem in production! We have several microservices and only one endpoints under heavy loading after 10/30 mins goes down. We suspect is due to a memory leak, we scale up but the problem remains. I'm using hapi-mongojs wrapper. The code is so simple that we don't know what change
findProducts(code) {
return new Promise((resolve, reject) => {
...
products.findOne({code}, {cs: 1, code: 1, _id: 0}, (error, document) => {
if (error) {
logger.log('error', error);
reject(Boom.badData('Internal MongoDB error', error));
} else {
resolve({ code: code, relations: this.invokeXXX(document) });
}
});
});
Any suggestions? Thanks
@niqdev I have moved to mongoose. It's due to mongojs's weak connection pool management, I guess.
@thatisuday So, I think we will do the same or move directly to native in this case. Thanks
@niqdev Please do that. mongoose is just super awesome. It will save you time and energy. You don't need to do separate validations. Also it provides SQL like joins. There are tons of good stuff. For overview, I have written a blog about it, please see this if you find it useful.
http://gitmeet.com/post/mongoose-js-part-1-in-a-nutshell http://gitmeet.com/post/mongoose-part-2-in-depth-look
Native... Too much hardwork I guess.
Thanks! I will have a look!