I'm using nodetime to analyze the high CPU usage of my node.js app.
Over 30% of the CPU usage is coming from Mongoose:
The next biggest culprit, at a mere 5%, is the Garbage Collector.
I believe I've heard, before, that Mongoose can cause high CPU usage, and that it can be preferable to skip it and directly use the Mongo driver. Is this accurate?
Here's the "Geocode.decodeMnay" function, triggered this particular hotspot...
Geocode.prototype.decodeMany = function(strs, callback)
{
var or = [],
map = {},
fields = {'woeid': 1, 'matched_queries': 1, 'latitude': 1, 'longitude': 1, 'radius': 1, 'name': 1},
unique = [];
strs = _.uniq(strs);
for(var k=0; k<strs.length; k++)
or.push({'matched_queries':strs[k].trim()});
this.model.find({$or: or}, fields, (function(e,matches){
// ... excluded for brevity
}).bind(this));
};
How else might I speed up this hotspot?
note that it is not the query taking a long time, as you can see, but rather the Mongo driver which is taking a long time to process the results (and consuming lots of CPU in the process).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…