I'm trying to improve my app's performance , and read that it's good practice to create multiple client connections so that mongodb can process queries in parallel (each client connection's queue being processed synchronously)
I'm using mongoose, and reading the connection docs, I see that you can set poolSize (default is 5). I haven't set the poolsize on my connections, so assuming it should be the default 5
var mongoOptions = {
server: {
poolSize: Number(process.env.MONGO_POOLSIZE) || 5
}
}
mongoose.connect(DATABASE_URL + "?authMechanism=SCRAM-SHA-1", mongoOptions);
Ran db.serverStatus().connections
in my mongo client, and see the below response
{ "current" : 9, "available" : 195, "totalCreated" : NumberLong(2058) }
I know that includes the mongo shell connection, but why is it 9 current connections vs 6? When I disconnect my server it goes down to 1 as expected.
Then if if I do set poolSize to 180 , I still get the 9 connections vs my settings.
Could someone explain
- how does mongoose connection pool work
- Why is my poolSize doesn't get applied, and
- Does having multiple connections mean that my queries would get process in parallel by mongo db ? or does one mongoose connections means one client connection?