I am using jessenger package for mongo db connection in lumen.
Issue I am facing is that each api open up a new mongo db connection. which turns out to be bulk of idle db connections of servers resulting wastage of resources and slowness of server.
Server is using php-fpm
. I have tried solution for pm=ondemand
with timeout
of 10 senconds. It worked quite good but failed the stress testing badly because application is largescale.
I am looking for a recommended solution which anyone has already tested to get the idle mongo db connections closed in mongo db.
2
Answers
You should be able to close it from the MongoDB side similar to https://dba.stackexchange.com/a/235081. 10 seconds may be too long for your needs; you can set maxIdleTimeMS in milliseconds.
https://www.mongodb.com/docs/manual/tutorial/connection-pool-performance-tuning/ gives a few thoughts on best practices for connection pools.
Performance has a number of factors that are outside of the direct question that may be interfering with your stress test. Long running operations, number of connections, inefficient queries are but a few issues that can affect performance outside of idle connections. You can see a start on the topic at https://www.mongodb.com/docs/manual/administration/analyzing-mongodb-performance/. There are entire books on the topic.
Try
maxIdleTimeMS
in connection