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

ajout de documentation sur le nombre de connexions et de threads max #5118

Draft
wants to merge 6 commits into
base: production
Choose a base branch
from

Conversation

adipasquale
Copy link
Contributor

Contexte

Victor est en train d’essayer de réduire le nombre de connexions ouvertes à la base de données pour résoudre les problèmes de mémoire lors des deploys.

Solution

Je rajoute un script qui permet de calculer un instantané des différentes valeurs de config en prod sur RDVS pour générer deux tableaux :

  • le nombre max de connexions à la db
  • le nombre max de threads

J’ai copié collé ce tableau dans le fichier de doc markdown notes techniques et j’ai rajouté des infos de contexte.

J’ai aussi rajouté des liens in situ vers cette nouvelle doc.

@@ -37,6 +37,9 @@ default: &default
#
#
# For GoodJob container, pool size is GOOD_JOB_MAX_THREADS (5) + 3 (1 for LISTEN/NOTIFY, 2 for CRON)
#
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@francois-ferrandis mon commentaire porte sur la ligne au dessus :

Ce n’est pas ce que je comprends de la doc de goodjob https://github.com/bensheldon/good_job?tab=readme-ov-file#database-connections

2 additional connections that GoodJob uses for utility functionality (e.g. LISTEN/NOTIFY, cron, etc.)

peut-être que ça a évolué depuis le temps où tu avais regardé ?

@victormours Il y a aussi deux autres lignes que j’ai du mal à comprendre

1 connection per execution pool thread. E.g., --queues=mice:2;elephants:1 is 3 threads and thus 3 connections. Pool size defaults to --max-threads.
1 connection per subthread, if your application makes multithreaded database queries (e.g. load_async) within a job.

Je ne comprends pas bien si ça veut dire que ce sont des connexions supplémentaires aux connexions ouvertes dans le pool ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non, ça veut dire qu'il faut dimensionner le pool pour fournir assez de connexions à Goodjob (et c'est bien le cas pour nous vu notre database.yml)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne vois aucune modification de cette section du README depuis que j'ai rédigé ce commentaire, donc le plus probable c'est que je me sois trompé à l'époque !

Non, ça veut dire qu'il faut dimensionner le pool pour fournir assez de connexions à Goodjob (et c'est bien le cas pour nous vu notre database.yml)

C'est effectivement ce que cette phrase du README laisse entendre :

The executor process will not crash if the connections pool is exhausted[...]

Et sinon, pour éprouver ma compréhension du sujet, cette liste dans le README exprime "le nombre de connexions potentiellement ouvertes en même temps" et non pas "le nombre de connexion ouvertes en permanence", c'est ça ?

Copy link
Contributor

@francois-ferrandis francois-ferrandis Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, mais en fait le README est incohérent entre la liste

https://github.com/bensheldon/good_job/blob/main/README.md?plain=1#L1145

et la suggestion de config

https://github.com/bensheldon/good_job/blob/main/README.md?plain=1#L1185

pool: <%= 1 + 2 + ENV.fetch("GOOD_JOB_MAX_THREADS", 5).to_i %>

Pourquoi 1 + 2, à quoi correspond le 1 ?

config/puma.rb Outdated
@@ -32,6 +35,9 @@
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }

# NOTE: Cette variable d’env est quand même respectée même quand la ligne au dessus est commentée !
# Elle est actuellement définie à 2 ou 3 sur les instances de production.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

justement depuis #5120 la variable d'env a été supprimée

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mis à jour merci ! 2f777c3

|-------------------------------|-----|------| --------------- | ---------------------- |
| scalingo_workers_count | 8 | 2 | - | `scalingo scale` |
| processes_per_worker | 3 | 1 | WEB_CONCURRENCY | config/puma.rb |
| connection_pools_max_sizes | 5 | 8 | GOOD_JOB_MAX_THREADS et RAILS_MAX_THREADS | config/database.yml |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modifié suite à #5120

Suggested change
| connection_pools_max_sizes | 5 | 8 | GOOD_JOB_MAX_THREADS et RAILS_MAX_THREADS | config/database.yml |
| connection_pools_max_sizes | 4 | 8 | GOOD_JOB_MAX_THREADS et RAILS_MAX_THREADS | config/database.yml |

| processes_per_worker | 3 | 1 | WEB_CONCURRENCY | config/puma.rb |
| connection_pools_max_sizes | 5 | 8 | GOOD_JOB_MAX_THREADS et RAILS_MAX_THREADS | config/database.yml |
| extra_connections_per_process | 0 | 3 | - | doc de GoodJob |
| total_max_connections | 120 | 22 | - | - |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| total_max_connections | 120 | 22 | - | - |
| total_max_connections | 96 | 22 | - | - |

| extra_connections_per_process | 0 | 3 | - | doc de GoodJob |
| total_max_connections | 120 | 22 | - | - |

Soit un total de 142 connexions à la base PostgreSQL ouvertes simultanées possibles.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Soit un total de 142 connexions à la base PostgreSQL ouvertes simultanées possibles.
Soit un total de 118 connexions à la base PostgreSQL ouvertes simultanées possibles.

|-------------------------------|-----|------|
| scalingo_workers_count | 8 | 2 |
| processes_per_worker | 3 | 1 |
| max_threads_count_per_process | 5 | 5 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| max_threads_count_per_process | 5 | 5 |
| max_threads_count_per_process | 4 | 5 |

| scalingo_workers_count | 8 | 2 |
| processes_per_worker | 3 | 1 |
| max_threads_count_per_process | 5 | 5 |
| total_max_threads | 120 | 10 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| total_max_threads | 120 | 10 |
| total_max_threads | 96 | 10 |

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

Successfully merging this pull request may close these issues.

3 participants