loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.95k stars 1.07k forks source link

Connection Pooling on MongoDB #7014

Open bala-fashiondx opened 3 years ago

bala-fashiondx commented 3 years ago

We are using loopback-connector-mongodb@5.0.1 version to connect to mongo db . Our database admins are reporting that our application is using more connections and it is constantly growing. When they report issues , we just restart our applications and connection use count drops drastically (from 800 active connections to 500 connections on mongodb).

We need to implement connection pooling in loopback, but not sure on what settings needs to be done on the datasource.json file. Can you please give some suggestions.

dhmlau commented 3 years ago

Have you tried to use the settings in https://docs.mongodb.com/manual/reference/connection-string/index.html#connection-pool-options? LoopBack would just pass the configs to the mongodb node.js driver.

bala-fashiondx commented 3 years ago

I have tried this , but still facing the mongo db connection time out . The error that i am getting was ,

Datasource mongo fails to connect due to timeout - aborting method "stack":"Error: Timeout in connecting after 5000 ms\n at Timeout._onTimeout (/node_modules/loopback-datasource-juggler/lib/datasource.js:2617:10)\n at listOnTimeout (internal/timers.js:549:17)\n at processTimers (internal/timers.js:492:7)","level":"error","message":"Timeout in connecting after 5000 ms","timestamp":"2021-01-18 06:35:33"

dhmlau commented 3 years ago

By looking at the error you posted above, it seems like the connection is invalid? If you remove the connection pool related config properties, did it complain the same thing?

bala-fashiondx commented 3 years ago

yes . There was same results even pool related config was there or not . The service working fine for few minutes . If the request to service increase I can able see the number of connections increasing in mongodb. But even after the response send , the connections were not closing in mongodb . It goes on increasing..

vinutha93bnvs commented 3 years ago

I have similar issue and looking for some solutions.

Had a issue reported few days back, Refer https://github.com/strongloop/loopback-next/issues/7012

stale[bot] commented 3 years ago

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

stale[bot] commented 3 years ago

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.