Mongos connection pool understanding

We have a sharded cluster with 3 shards, and about 15 app servers that run mongos.

When I look at the mongos logs, I see a couple messages every second about connections being opened and then closed. The numOpenConns looks like it goes up to about 16… then it seems like the connections start to get ended. Is there any advantage of increasing the minimum pool size to something like 15 so the connections aren’t constantly created and ended? How would I do this in the mongos client?

{"t":{"$date":"2023-02-09T11:14:55.664-05:00"},"s":"I",  "c":"CONNPOOL", "id":22567,   "ctx":"TaskExecutorPool-0","msg":"Ending idle connection because the pool meets constraints","attr":{"hostAndPort":"d-db1:27017","numOpenConns":8}}
{"t":{"$date":"2023-02-09T11:15:00.082-05:00"},"s":"I",  "c":"CONNPOOL", "id":22567,   "ctx":"TaskExecutorPool-0","msg":"Ending idle connection because the pool meets constraints","attr":{"hostAndPort":"h-db1:27017","numOpenConns":8}}
{"t":{"$date":"2023-02-09T11:15:00.086-05:00"},"s":"I",  "c":"CONNPOOL", "id":22567,   "ctx":"TaskExecutorPool-0","msg":"Ending idle connection because the pool meets constraints","attr":{"hostAndPort":"h-db1:27017","numOpenConns":7}}
{"t":{"$date":"2023-02-09T11:15:06.443-05:00"},"s":"I",  "c":"CONNPOOL", "id":22567,   "ctx":"TaskExecutorPool-0","msg":"Ending idle connection because the pool meets constraints","attr":{"hostAndPort":"d-db1:27017","numOpenConns":7}}
{"t":{"$date":"2023-02-09T11:15:06.463-05:00"},"s":"I",  "c":"CONNPOOL", "id":22567,   "ctx":"TaskExecutorPool-0","msg":"Ending idle connection because the pool meets constraints","attr":{"hostAndPort":"d-db1:27017","numOpenConns":6}}
{"t":{"$date":"2023-02-09T11:15:07.664-05:00"},"s":"I",  "c":"CONNPOOL", "id":22567,   "ctx":"TaskExecutorPool-0","msg":"Ending idle connection because the pool meets constraints","attr":{"hostAndPort":"d-db1:27017","numOpenConns":5}}

Also, is there an easy way to determine the current values of --maxConns and --listenBacklog?

I do not see what the default value for -maxConns is in the documentation:

Hi @AmitG and welcome back to the MongoDbB community forum!!

According to the MongoDB specifications, an idle connection is the one which are present for longer time than the maxIdleTimeMS. Further as the specifications state, the connection being idle make them eligible for closing the connection, so I believe this is part of the connection pool maintenance.
Please refer to the documentation on Connection pooling and the setting to be followed for connection pooling for the application for more details

For maxConns, since this is a server parameter, you can find the value set for the specific deployment using the below command:

     getCmdLineOpts: 1

while the default value for listenBacklog is SOMAXCONN .
The server ticket mentions that the value is made configurable since version 3.4.6.

Let us know if you have any more questions.

Best Regards