-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mongoose Performance Regression 4.13 -> 5.5 #7895
Comments
Quick Update: It appears under the same conditions, using
|
So, it looks like our best bet is to roll with the suggested One last test under the same dependencies (5.x) + concurrency (2)
|
@mpseay can you try |
Sure thing! Same test with
|
It's worth mentioning some additional conditions around this test. The model I am using is a little larger than you might expect. But, more importantly, it contains document references to other collections and takes advantage of the mongoose I wanted to get an idea of the overhead, and, as expected, the more |
How about increasing the poolSize? Since you have 9 population, you send 10
query requests to MongoDB in a single http request. Try set up poolSize
options of mongoose connection to 50 to see if this helps
|
Happy to share more results. But, poolSize didn't make a difference in this case.
|
Realistically, I'm not going to be able to repro this without taking a look at what your schema looks like. Below script gives similar perf results for me between Mongoose 4 and Mongoose 5: const express = require('express');
const mongoose = require('mongoose');
run().catch(error => console.error(error));
async function run() {
await mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true });
await mongoose.connection.dropDatabase();
const Model = mongoose.model('Test', mongoose.Schema({ name: String }));
const doc = await Model.create({ name: 'test' });
const app = express();
app.get('*', function(req, res) {
Model.findById(doc._id).exec((data) => {
if (!data) {
return res.send(404);
}
return res.send({result: data});
}, (e) => {
return res.send(500);
});
});
await app.listen(3000);
console.log('Listening on port 3000');
} Mongoose 5:
Mongoose 4:
|
I'm also seeing what looks like a performance regression between 4.13 and 5.6 (in my case specifically 4.13.8 and 5.6.5), under real workloads. CPU usage looks elevated by about 30% in 5.6.5 over 4.13.8, and there is a perceptible effect on response time. I did some performance analysis on a realistic simulation of our production workload, and it looks like 5.6 is spending a lot of time in Document.__init, particularly when subdocuments are involved. I wrote a little script to compare .init() performance between 4 and 5. Subdoc array init looked like it might have something to do with it, so I used a fairly beefy subdoc array:
In mongoose 4.13.8, running that generally gives:
In mongoose 5.6.5 (5.6.7 is about the same), I get:
... and that's pretty consistent across several runs, so that'd be document init taking about 1.5 times as much time (and, since synchronous, probably CPU as well) as it did under Mongoose 4. Does that seem like it might be a lead? It looks like our application is fairly sensitive to Mongoose document init performance, and I would imagine that the other reporters' might be as well. |
@brettkiefer that was very helpful, helped confirm that the perf issue here was with document arrays. I put in a PR: #8037 that expands on the work in #7798 and shaves off 30% on the |
@vkarpov15 That looks great! For the above perf script on my test setup, 11ce670 runs much faster than 5.6.5 and only slightly slower than 4.13.8 under node 10.15.3, so that should translate to big improvements for our real-world workload. Thanks for looking at it. |
Awesome news! |
Hey Guys! I've found a few documented cases where a performance regression was found. Specifically, #6065 lead me to checking on the versions for
mongodb
andmongodb-core
. After troubleshooting this for most the day, our database has been totally fine, but, the mongoose upgrade is clearly bottlenecking somewhere I can't seem to figure out. Any help in the right direction would be greatly appreciated!System Setup
Node Version: 6.11
Database Version: 3.6
npm mongoose versions: 4.13 / 5.5.13
npm mongodb: 3.2.7
npm mongodb-core: 3.2.7
Sample Code
Testcase Description
An express app doing a super basic findById() lookup.
Notice the large difference between the versions.
Mongoose 4.13
Mongoose 5.5.13
The text was updated successfully, but these errors were encountered: