How Mongoose poolSize works

I am trying to improve the performance of my application and read that it is good practice to create multiple client connections so that mongodb can handle requests in parallel (each client connection queue is processed synchronously)

I use mongoose and read connection documents, I see that you can set poolSize (default is 5). I did not set up a pool in my connections, therefore, assuming this should be the default value of 5

var mongoOptions = {
        server: {
            poolSize: Number(process.env.MONGO_POOLSIZE) || 5
        }
    }
mongoose.connect(DATABASE_URL + "?authMechanism=SCRAM-SHA-1", mongoOptions);

Ran db.serverStatus().connectionsin my mongo client and see below answer { "current" : 9, "available" : 195, "totalCreated" : NumberLong(2058) }

I know that includes a mongo shell connection, but why is it 9 current connections versus 6? When I shut down my server, it will drop to 1 as expected.

Then, if I set poolSize to 180, I still get 9 connections against my settings.

Can someone explain

  • How the mongoose pool works
  • Why is my poolSize not applicable, and
  • Does multiple connections mean that my requests will be processed in parallel with mongo db? or does one mongoose connection mean one client connection?
+4
source share

Source: https://habr.com/ru/post/1672431/


All Articles