Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection poolSize limit? #6206

Closed
imdonaldjohn opened this issue Mar 5, 2018 · 5 comments
Closed

Connection poolSize limit? #6206

imdonaldjohn opened this issue Mar 5, 2018 · 5 comments
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity

Comments

@imdonaldjohn
Copy link

Forgive me if there's already been an answer to this somewhere, but I haven't seen anything definitive in the docs.

Is there a limit to the size of the connection pool?
I have a situation where there could be 100s or 1000s of connections open at once - should the connection pool be used for this or would that be an abuse of the feature?

@vkarpov15
Copy link
Collaborator

There's a poolSize option you can use to configure that: http://mongoosejs.com/docs/connections.html#options . By default, the limit is 5.

Can you clarify what you mean by "100s or 1000s of connections"?

@vkarpov15 vkarpov15 added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity labels Mar 7, 2018
@imdonaldjohn
Copy link
Author

@vkarpov15 sure thing. When users log into the app, they will need to be able to switch between different databases (one at a time) and perform CRUD operations on whichever database they're connected to at the time.

My problem is with how this is going to scale. If I have potentially 1000 (or more) users logged in, performing operations on different databases, will mongoose be able to handle that with pools (ie. 1 pool connection per person logged in) or should I maybe create a new mongoose instance per new database connection?

There could also be overlap (ie. 5 users logged in performing operations onto the same DB).

@imdonaldjohn
Copy link
Author

After taking a second glance at the docs http://mongoosejs.com/docs/connections.html it sounds like I can't leverage the connection pool to facilitate writing/reading to different databases. It sounds like the connection pool only makes connecting to any one database more efficient which is nice.

I think what I'll have to do is create multiple mongoose connections using createConnection() as those new database connections are needed and close them out when no one's using them.
This seems expensive but I'm not sure of any other way to really do it.

@vkarpov15
Copy link
Collaborator

For your application I think multiple connection pools is the way to go. Ultimately it comes down to the fact that mongodb can only make progress on one operation per socket connection at a time, so if you just have 5 sockets in your pool and you have 5 very slow operations running, any fast operations that come in will be blocked. If you have different databases and different users with very different workloads, one user might slow down other users.

Also, FYI, we don't really have this documented well yet, but we have the option to cache connections to useDb(), so we have the option to not create a new connection pool on every useDb() call: #6036

@imdonaldjohn
Copy link
Author

@vkarpov15 sounds good, thanks for the heads up about the caching as well - I think I can make use of that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary needs clarification This issue doesn't have enough information to be actionable. Close after 14 days of inactivity
Projects
None yet
Development

No branches or pull requests

2 participants