Commit 19a83ec7 authored by Philippe Pepiot's avatar Philippe Pepiot
Browse files

[server] Make connection pooler configurable and set better default values

Drop the configuration connections-pool-size and add new configurations options:

* connections-pool-min-size. Set to 0 by default so we open connections only
  when needed. This avoid opening min-size*processes connections at startup,
  which is, it think, a good default.
* connections-pool-max-size. Set to 0 (unlimited) by default, so we move the
  bottleneck to postgresql.
* connections-idle-timeout. Set to 10 minutes. I don't have arguments about
  this except that this is the default in pgbouncer.
parent 36329bb3f891
......@@ -263,11 +263,16 @@ class _CnxSetPool(_BaseCnxSet):
def get_cnxset(config, source, bootstrap=False):
if not config['connections-pooler-enabled']:
return _BaseCnxSet(source)
idle_timeout = config['connections-pool-idle-timeout']
if bootstrap or config.quick_start:
max_size = 1
min_size, max_size = 0, 1
max_size = config['connections-pool-size']
return _CnxSetPool(source, min_size=1, max_size=max_size)
min_size, max_size = (
return _CnxSetPool(source, min_size=min_size, max_size=max_size,
class Repository(object):
......@@ -132,11 +132,22 @@ the repository rather than the user running the command',
'help': 'Enable the connection pooler. Set to no if you use an external database pooler (e.g. pgbouncer)',
'group': 'main', 'level': 3,
{'type' : 'int',
'default': 4,
'help': 'size of the connections pool. Each source supporting multiple \
connections will have this number of opened connections.',
'default': 0,
'help': 'Maximum, per process, number of database connections. Default 0 (unlimited)',
'group': 'main', 'level': 3,
{'type' : 'int',
'default': 0,
'help': 'Minimum, per process, number of database connections.',
'group': 'main', 'level': 3,
{'type' : 'int',
'default': 600,
'help': "Start closing connection if the pool hasn't been empty for this many seconds",
'group': 'main', 'level': 3,
......@@ -196,12 +196,12 @@ class CubicWebConfigurationTC(BaseTestCase):
del os.environ['CW_BASE_URL']
def test_config_value_from_environment_int(self):
self.assertEqual(self.config['connections-pool-size'], 4)
os.environ['CW_CONNECTIONS_POOL_SIZE'] = '6'
self.assertEqual(self.config['connections-pool-max-size'], 0)
os.environ['CW_CONNECTIONS_POOL_MAX_SIZE'] = '6'
self.assertEqual(self.config['connections-pool-size'], 6)
self.assertEqual(self.config['connections-pool-max-size'], 6)
del os.environ['CW_CONNECTIONS_POOL_SIZE']
def test_config_value_from_environment_yn(self):
self.assertEqual(self.config['allow-email-login'], False)
......@@ -6,3 +6,5 @@ Changes
- the class cubicweb.view.EntityAdapter was moved to cubicweb.entity.EntityAdapter
a deprecation warning is in place, but please update your source code accordingly.
- The database pooler is now dynamic. New connections are opened when needed and closed after a configurable period of time. This can be configured through `connections-pooler-max-size` (default 0, unlimited), `connections-pooler-min-size` (default 0), and `connections-pooler-idle-timeout` (default 600 seconds). The old configuration `connections-pooler-size` has been dropped.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment