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

MongoDB connection pool size #92

Open
jim3692 opened this issue Mar 29, 2020 · 2 comments
Open

MongoDB connection pool size #92

jim3692 opened this issue Mar 29, 2020 · 2 comments

Comments

@jim3692
Copy link

jim3692 commented Mar 29, 2020

I was stress testing the app in a local server and I discovered that the responses are sent in batches of 5. After some research I found that mongoose uses its default connection pool size, which is 5 (documentation). However, MongoDB's native driver has a default of 100 connections (documentation).

I would recommend changing mongoose.connect call in app.js to:

mongoose.connect(config.MONGO[process.env.NODE_ENV], {
  connectTimeoutMS: 120000,
  socketTimeoutMS: 120000,
  poolSize: 100 // MongoDB's default
})
@apavlidi
Copy link
Owner

apavlidi commented Mar 30, 2020

Hi @jim3692

Can you please provide your stress test technique/data sets and the results before/after the change? It would be very helpful for us to reproduce and verify your suggestion.

Thank you for your contribution

@jim3692
Copy link
Author

jim3692 commented Mar 30, 2020

The first test I run was inaccurate since I used Chrome and Firefox to run the test. However, both browsers have a limit of 6 parallel connections (as mr. @asidirop noted in a personal email). I run new tests on /announcements/public, which does not need authentication, using Apache Bench.

The results showed that, when the pool size is higher than the concurrency in Apache Bench, the API needs less time to respond to other requests that need access to the database.

We also tried to change this value in the production server and we saw an improvement when the server is stressed with an Apache Bench instance running in https://users.iee.ihu.gr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants