mongoose: 10x slowdown on Windows when upgrading from Mongoose 4 to 5.
My tests are taking 10x as long on Windows when I upgrade from Mongoose 4 to 5. The slowdown doesn’t appear to happen on my Ubuntu laptop.
I created a repo with two branches to illustrate the problem, https://github.com/deklanw/pensieve-mongoose-4-to-5-speed-testing
I included the .env file for testing. If need be just change this line
MONGODB_URI=mongodb://localhost:27017/pensieve-test
to reflect your testing environment.
Just,
yarn install
yarn test
I tested on my Windows desktop and laptop to make sure. They’re both Windows 10 x64. The problem occurred on both. The problem doesn’t occur on my Ubuntu laptop.
Here are the versions:
Windows 10 x64 laptop: mongodb v3.6.5 node v10.1.0 yarn v1.6.0
Windows 10 x64 desktop: mongodb v3.6.3 node v10.3.0 yarn v1.7.0
The Ubuntu laptop has the same versions of everything as the Windows 10 desktop.
@lineus Tested this on OSX, I believe, and didn’t find the slowdown. So it appears to be Windows related.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21 (2 by maintainers)
@NewEraCracker is spot on, good call. The reason for this slowdown is that, starting in mongodb driver 3.0.0, the mongodb driver tries to connect using ipv6 first, and falls back to ipv4 if that fails unless you set the
family
option or use an ipv4 address like 127.0.0.1. The 1 second delay is because the driver’s trying to connect to localhost using ipv6, but presumably either your mongodb server isn’t configured to accept ipv6 connections orlocalhost
isn’t configured to point to an ipv6 address. Below are the relevant linkshttps://github.com/mongodb-js/mongodb-core/commit/107bae5083d40b8521b5796469ddbc3ea2063c7a https://jira.mongodb.org/projects/NODE/issues/NODE-1222?filter=allissues https://github.com/mongodb-js/mongodb-core/pull/260
As a workaround, do this:
We’ll add documentation around this option
Yeah I can confirm that switching to 127.0.0.1 from localhost speeds up initial connection from 1000ms to 30ms on windows. Currently digging in to why this is the case.
Already switched to 127.0.0.1 in the connection string, and the tests run much faster now.
Thank you!
Are you connecting by name or IP?
On the example you posted, you documented
localhost
, if you replace that with127.0.0.1
does it workaround the issue?Regards, NewEraCracker
a
bug?
label would be great,needs repro script
on an issue that’s been abandoned for a while may give the wrong idea to the developers.Perhaps we should remove the
needs repro script
label from this issue now? I believe https://github.com/Automattic/mongoose/issues/6566#issuecomment-397935727 is a good start.It’s not just the connection either, deleting, and creating data are 10x+ slower as well.
Using the following code:
v4.13.14 outputs:
v5.1.5 outputs: