From eb31778c240e42c0875921b88dd62b81c3118f11 Mon Sep 17 00:00:00 2001 From: James Page Date: Tue, 7 Oct 2014 13:28:20 +0100 Subject: [PATCH] Add support for worker process configuration --- config.yaml | 7 +++++++ .../charmhelpers/contrib/openstack/context.py | 19 +++++++++++++++++++ hooks/glance_utils.py | 6 ++++-- templates/icehouse/glance-api.conf | 1 + templates/icehouse/glance-registry.conf | 1 + 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/config.yaml b/config.yaml index 7ffbbd09..c3dc16aa 100644 --- a/config.yaml +++ b/config.yaml @@ -146,3 +146,10 @@ options: order for this charm to function correctly, the privacy extension must be disabled and a non-temporary address must be configured/available on your network interface. + worker-multiplier: + type: int + default: 2 + description: | + The CPU core multiplier to use when configuring worker processes for + Glance. By default, the number of workers for each daemon is set to + twice the number of CPU cores a service unit has. diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index 173089f4..538dc913 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -903,3 +903,22 @@ class BindHostContext(OSContextGenerator): return { 'bind_host': '0.0.0.0' } + + +class WorkerConfigContext(OSContextGenerator): + + @property + def num_cpus(self): + try: + from psutil import NUM_CPUS + except ImportError: + apt_install('python-psutil', fatal=True) + from psutil import NUM_CPUS + return NUM_CPUS + + def __call__(self): + multiplier = config('worker-multiplier') or 1 + ctxt = { + "workers": self.num_cpus * multiplier + } + return ctxt diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index 139d8a7e..5128968d 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -83,7 +83,8 @@ CONFIG_FILES = OrderedDict([ context.IdentityServiceContext(), context.SyslogContext(), glance_contexts.LoggingConfigContext(), - glance_contexts.GlanceIPv6Context()], + glance_contexts.GlanceIPv6Context(), + context.WorkerConfigContext()], 'services': ['glance-registry'] }), (GLANCE_API_CONF, { @@ -96,7 +97,8 @@ CONFIG_FILES = OrderedDict([ glance_contexts.HAProxyContext(), context.SyslogContext(), glance_contexts.LoggingConfigContext(), - glance_contexts.GlanceIPv6Context()], + glance_contexts.GlanceIPv6Context(), + context.WorkerConfigContext()], 'services': ['glance-api'] }), (GLANCE_API_PASTE_INI, { diff --git a/templates/icehouse/glance-api.conf b/templates/icehouse/glance-api.conf index 0b2e42f7..a4e08f2c 100644 --- a/templates/icehouse/glance-api.conf +++ b/templates/icehouse/glance-api.conf @@ -2,6 +2,7 @@ verbose = {{ verbose }} use_syslog = {{ use_syslog }} debug = {{ debug }} +workers = {{ workers }} {% if rbd_pool -%} default_store = rbd diff --git a/templates/icehouse/glance-registry.conf b/templates/icehouse/glance-registry.conf index bbd1c31f..f7dde09f 100644 --- a/templates/icehouse/glance-registry.conf +++ b/templates/icehouse/glance-registry.conf @@ -2,6 +2,7 @@ verbose = {{ verbose }} use_syslog = {{ use_syslog }} debug = {{ debug }} +workers = {{ workers }} bind_host = {{ bind_host }} bind_port = 9191