mongodb connection takes ~10 seconds

Viewed 185

My Node.js application has a MongoDB connection, which when running on localhost connects immediately. When I'm running it on a shared hosting server, it takes at least 10 sec to connect every time. What I have tried so far, but did not help: changing connection parameters as follows:

    useNewUrlParser: true,
    useUnifiedTopology: true,
    connectTimeoutMS:3600000,
    keepAlive:3600000,
    socketTimeoutMS:3600000

Also tried using MongoHeartbeat to keep the connection alive, but it did not help.

1 Answers

keepalive probably needs to be lower, not higher. but 10 seconds sounds a lot like a timeout, can you get better logs? is there a proxy like nginx in between that cuts the connection? do you control all involed machines?

Related