Mongoose (node.js module) causes high CPU usage

前端 未结 1 1151
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 07:33

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:

相关标签:
1条回答
  • 2020-12-18 08:02

    With Mongoose, it's important to use the lean option for queries with large result sets where you don't need anything but the plain JavaScript documents themselves. That should provide performance comparable to using the native driver directly.

    For example, in the case above it would be:

    this.model.find({$or: or}, fields).lean().exec(function(e, matches) {
        // ... excluded for brevity
    }).bind(this));
    
    0 讨论(0)
提交回复
热议问题