-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
4.7.7 -> 5.13.21 reduction performance #14113
Comments
when #14120 was applied only, there was no significant change in mongoose v5 performance. please additionally check if there are any other factors. And apply the contents in the mongoose v5 version as well. I will refer to your performance improvement. 🙇🏻 |
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days |
Will other improvements be reflected in v5? |
@0Ams we aren't backporting anything other than security fixes and requested bug fixes to Mongoose 5, and Mongoose 5 is scheduled for EOL in March 2024, so about 2 months from now: https://mongoosejs.com/docs/version-support.html. Here's the results I'm seeing from the following script:
Mongoose 4:
Mongoose 5:
Mongoose 6:
Mongoose 7:
We're going to debug this performance degradation and see how easy this is to backport to Mongoose 5. At the very least, we will backport any performance improvements to Mongoose 6, which I would recommend you upgrade to. |
Took me way too long to notice this, but your tests are actually profiling |
did your test use the latest version of each mongoose version? so I'm inquiring again. is it no longer backport to mongoose 5 for information on performance improvement and @add question
If
|
The |
I appreciate your help. 😄 |
Looking more closely I created the following simplified script for better flamegraphs: const mongoose = require('mongoose');
const DATA_AMOUNT = {min: 40, max: 400};
console.log(mongoose.version);
async function run() {
await mongoose.connect('mongodb://localhost:27017/mongoose_test');
const Model = mongoose.model('Test', new mongoose.Schema({
randomNumberData: [Number],
randomStringData: [String]
}));
if (process.env.SETUP) {
await setup(Model);
}
const reps = 500;
let total = 0;
for (let i = 0; i < reps; ++i) {
total += await profile(Model, await Model.findOne());
}
console.log(`mongoose spendTime:`, total, 'average:', total / reps);
process.exit(0);
}
async function setup(Model) {
//await Model.remove({});
await Model.deleteMany({});
for (let i = 0; i < 200; ++i) {
const record = new Model();
for (let i = 0; i < Math.random() * (DATA_AMOUNT.max - DATA_AMOUNT.min) + DATA_AMOUNT.min; ++i) {
const random = Math.random();
record.randomNumberData.push(random);
record.randomStringData.push(`${random}`);
}
await record.save();
}
console.log('Setup done');
}
async function profile(Model, doc) {
let totalMS = 0;
const cursor = Model.find().cursor();
for (let i = 0; i < 200; ++i) {
const start = Date.now();
await Model.findById(doc._id);
totalMS += Date.now() - start;
}
return totalMS;
}
run().catch((error) => console.error(error.stack)); On 4.x:
On 5.x:
Below is the 5.x flamegraph, which shows that the vast majority of the time is spent either in the Node driver or waiting on the MongoDB server, but there's still a decent amount of time spent in Mongoose For comparison, here is output when using Mongoose 5 with
Here is flamegraph with Still WIP, but it's looking like the issue would be in |
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days |
I'm still waiting for updating it |
perf(document+schema): small optimizations to make `init()` faster
Prerequisites
Mongoose version
5.13.21
Node.js version
18.15.0
MongoDB version
4.4.25
Operating system
None
Operating system version (i.e. 20.04, 11.3, 10)
No response
Issue
Context
Test Code
Result
The text was updated successfully, but these errors were encountered: