【发布时间】:2013-02-12 09:23:40
【问题描述】:
我正在使用 nodetime 来分析我的 node.js 应用程序的高 CPU 使用率。 超过 30% 的 CPU 使用率来自 Mongoose:
第二大罪魁祸首(仅占 5%)是垃圾收集器。
我相信我之前听说过 Mongoose 会导致 CPU 使用率过高,最好跳过它并直接使用 Mongo 驱动程序。这准确吗?
这里是“Geocode.decodeMnay”函数,触发了这个特定的热点...
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));
};
我还能如何加速这个热点?
注意,正如您所见,不是查询花费了很长时间,而是 Mongo 驱动程序花费了很长时间来处理结果(并且在过程)。
【问题讨论】: