diff --git a/config.yaml b/config.yaml index dcc0df48..aeb292d9 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 c47b9c19..1cc1067a 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, { @@ -97,6 +98,7 @@ CONFIG_FILES = OrderedDict([ context.SyslogContext(), glance_contexts.LoggingConfigContext(), glance_contexts.GlanceIPv6Context(), + context.WorkerConfigContext(), glance_contexts.MultiStoreContext()], 'services': ['glance-api'] }), 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 diff --git a/templates/juno/glance-api.conf b/templates/juno/glance-api.conf index dea92c6c..c777c5fa 100644 --- a/templates/juno/glance-api.conf +++ b/templates/juno/glance-api.conf @@ -2,6 +2,7 @@ verbose = {{ verbose }} use_syslog = {{ use_syslog }} debug = {{ debug }} +workers = {{ workers }} known_stores = {{ known_stores }} {% if rbd_pool -%}