You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
6.1 KiB

  1. ==================
  2. Bus Alt Connection
  3. ==================
  4. .. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5. !! This file is generated by oca-gen-addon-readme !!
  6. !! changes will be overwritten. !!
  7. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  8. .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
  9. :target: https://odoo-community.org/page/development-status
  10. :alt: Beta
  11. .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
  12. :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
  13. :alt: License: AGPL-3
  14. .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
  15. :target: https://github.com/OCA/server-tools/tree/12.0/bus_alt_connection
  16. :alt: OCA/server-tools
  17. .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
  18. :target: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-bus_alt_connection
  19. :alt: Translate me on Weblate
  20. .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
  21. :target: https://runbot.odoo-community.org/runbot/149/12.0
  22. :alt: Try me on Runbot
  23. |badge1| |badge2| |badge3| |badge4| |badge5|
  24. This module makes it possible to use PgBouncer_ as a connection pooler
  25. for odoo.
  26. .. _PgBouncer: https://pgbouncer.github.io/
  27. Why isn't odoo's connection pooling good enough?
  28. ================================================
  29. Odoo's builtin connection pooling works at process level: each Odoo process
  30. has its own ConnectionPool_, limited to ``db_maxconn``.
  31. It does the job of re-using open connections available in the pool.
  32. But it never closes these connections, `unless reaching db_maxconn`_.
  33. .. _ConnectionPool: https://github.com/odoo/odoo/blob/12.0/odoo/sql_db.py#L525
  34. .. _`unless reaching db_maxconn`: https://github.com/odoo/odoo/blob/12.0/odoo/sql_db.py#L593
  35. In practice, we observe that each odoo worker will end up
  36. with up to 3 open connection in its pool.
  37. With 10 http workers, that's up to 30 connection continuously open just
  38. for one single instance.
  39. Here comes PgBouncer
  40. ====================
  41. PgBouncer will help to limit this number of open connections,
  42. by sharing a pool of connections at the instance level, between
  43. all workers. Odoo workers will still have up to 3 open connections,
  44. but these will be connections to PgBouncer, that on its side will
  45. close unnecessary connections to pg.
  46. This has proven to help performances on Odoo deployments with
  47. multiple instances.
  48. It allows you to define how resources should be shared,
  49. according to your priorities, e.g. :
  50. * key odoo instance on host A can open up to 30 connections
  51. * while odoo instance on host B, dedicated to reports,
  52. can open up to 10 connections only
  53. And most importantly, it helps you to ensure that
  54. ``max_connections`` will never be reached on pg server side.
  55. Why is this module needed?
  56. ==========================
  57. When configuring PgBouncer, you can choose between 2 transaction pooling modes:
  58. * `pool_mode = session`
  59. * `pool_mode = transaction`
  60. If we choose `pool_mode = session`, then one server connection will be tied
  61. to a given odoo process until its death, which is exactly what we're trying
  62. to change. Thus, to release the server connection once the transaction is
  63. complete, we use `pool_mode = transaction`.
  64. This works fine, except for Odoo's longpolling features that relies
  65. on the `LISTEN/NOTIFY`_ mechanism from pg, which is `not compatible`_ with that
  66. mode.
  67. .. _`LISTEN/NOTIFY`: https://www.postgresql.org/docs/9.6/static/sql-notify.html
  68. .. _`not compatible`: https://wiki.postgresql.org/wiki/PgBouncer
  69. To be more precise, `NOTIFY` statements are properly transfered by PgBouncer
  70. in that mode; only the `LISTEN` statement isn't (because it needs to keep the
  71. server connection open).
  72. So for the unique "listening" connection per instance that requires this
  73. statement (here_), we need odoo to connect directly to the pg server, bypassing
  74. PgBouncer.
  75. That's what this module implements, by overriding the relevant method
  76. of the Dispatcher_.
  77. .. _here: https://github.com/odoo/odoo/blob/12.0/addons/bus/models/bus.py#L166
  78. .. _Dispatcher: https://github.com/odoo/odoo/blob/12.0/addons/bus/models/bus.py#L105
  79. **Table of contents**
  80. .. contents::
  81. :local:
  82. Installation
  83. ============
  84. You don't need to install this module in the database(s) to enable it.
  85. But you need to load it server-wide:
  86. * By starting Odoo with ``--load=web,bus_alt_connection``
  87. * Or by updating its configuration file:
  88. .. code-block:: ini
  89. [options]
  90. (...)
  91. server_wide_modules = web,bus_alt_connection
  92. Configuration
  93. =============
  94. You need to define how to connect directly to the database:
  95. * Either by defining environment variables:
  96. - ``IMDISPATCHER_DB_HOST=db-01``
  97. - ``IMDISPATCHER_DB_PORT=5432``
  98. * Or in Odoo's configuration file:
  99. .. code-block:: ini
  100. [options]
  101. (...)
  102. imdispatcher_db_host = db-01
  103. imdispatcher_db_port = 5432
  104. Bug Tracker
  105. ===========
  106. Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
  107. In case of trouble, please check there if your issue has already been reported.
  108. If you spotted it first, help us smashing it by providing a detailed and welcomed
  109. `feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20bus_alt_connection%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
  110. Do not contact contributors directly about support or help with technical issues.
  111. Credits
  112. =======
  113. Authors
  114. ~~~~~~~
  115. * Trobz
  116. Contributors
  117. ~~~~~~~~~~~~
  118. * Nils Hamerlinck <nils@trobz.com>
  119. Maintainers
  120. ~~~~~~~~~~~
  121. This module is maintained by the OCA.
  122. .. image:: https://odoo-community.org/logo.png
  123. :alt: Odoo Community Association
  124. :target: https://odoo-community.org
  125. OCA, or the Odoo Community Association, is a nonprofit organization whose
  126. mission is to support the collaborative development of Odoo features and
  127. promote its widespread use.
  128. This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/12.0/bus_alt_connection>`_ project on GitHub.
  129. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.