openfoodfacts / openfoodfacts-server

Open Food Facts database, API server and web interface - 🐪🦋 Perl, CSS and JS coders welcome 😊 For helping in Python, see Robotoff or taxonomy-editor
GNU Affero General Public License v3.0
630 stars 366 forks source link

Implement mongodb connection pooling #3346

Open syl10100 opened 4 years ago

syl10100 commented 4 years ago

Why

Stats

These are the statistic about connections :

What

One best practice would be to implement connection pooling.

Part of

syl10100 commented 4 years ago

image

https://docs.mongodb.com/manual/faq/diagnostics/#faq-memory

stephanegigandet commented 4 years ago

I think we have one connection per Apache/mod_perl process, but each of them can serve multiple requests.

"Number of connections opened: 226286"

-> Do you have stats on the number of MongoDB queries during the same period? Is it 1 connection = 1 query?

syl10100 commented 4 years ago

We cannot get this information from mongodb log because all queries are not logged (only the one that last more than 100ms). However maybe we can check the perl log and see how often new connection to mongo is created ?

syl10100 commented 4 years ago

The production perl log in verbose mode shows that the number of mongodb connections created is not excessive : in 5 minutes, we got about 50 connections opened and 1700 connections reused.

That does not match the information we have in mongod.log where we can see about one connexion opened/closed every second.

raphael0202 commented 4 years ago

Connection pooling is however a good practice that usually increases latency significantly (at least for SQL DB, I've not much experience with MongoDB)

github-actions[bot] commented 6 months ago

This issue has been open 90 days with no activity. Can you give it a little love by linking it to a parent issue, adding relevant labels and projets, creating a mockup if applicable, adding code pointers from https://github.com/openfoodfacts/openfoodfacts-server/blob/main/.github/labeler.yml, giving it a priority, editing the original issue to have a more comprehensive description… Thank you very much for your contribution to 🍊 Open Food Facts