From f83296e07387affab9364b273c999f292e8c9905 Mon Sep 17 00:00:00 2001
From: Ravi Gummadi <ravigumm@in.ibm.com>
Date: Thu, 23 Feb 2017 05:45:47 -0500
Subject: [PATCH] Cap the number of worker threads

Users can configure the number of worker threads however when it's
not specified the calculated number of workers can get too large on
hosts with a large number of CPUs.

Change-Id: I6c950cc31b66479dc980ecd5eb580d403dd27ae6
---
 defaults/main.yml                                        | 5 ++++-
 .../notes/capping_nova_workers-349f0f4d3fd50b37.yaml     | 7 +++++++
 templates/nova.conf.j2                                   | 9 +++------
 3 files changed, 14 insertions(+), 7 deletions(-)
 create mode 100644 releasenotes/notes/capping_nova_workers-349f0f4d3fd50b37.yaml

diff --git a/defaults/main.yml b/defaults/main.yml
index 486cc662..d9b006b5 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -276,7 +276,9 @@ nova_placement_nginx_extra_conf:
   - keepalive_timeout   70;
 nova_placement_uwsgi_socket_port: 8781
 nova_wsgi_threads: 1
-nova_wsgi_processes: "{{ (ansible_processor_vcpus | int > 0) | ternary (ansible_processor_vcpus, 1) * 2}}"
+## Cap the maximum number of processes when a user value is unspecified.
+nova_wsgi_processes_max: 16
+nova_wsgi_processes: "{{ [[ansible_processor_vcpus|default(1), 1] | max * 2, nova_wsgi_processes_max] | min }}"
 nova_wsgi_buffer_size: 65535
 
 ## Nova libvirt
@@ -398,6 +400,7 @@ nova_ceph_client_uuid: 517a4663-3927-44bc-9ea7-4a90e1cd4c66
 
 ## Cap the maximun number of threads / workers when a user value is unspecified.
 nova_api_threads_max: 16
+nova_api_threads: "{{ [[ansible_processor_vcpus|default(2) // 2, 1] | max, nova_api_threads_max] | min }}"
 
 ## Policy vars
 # Provide a list of access controls to update the default policy.json with. These changes will be merged
diff --git a/releasenotes/notes/capping_nova_workers-349f0f4d3fd50b37.yaml b/releasenotes/notes/capping_nova_workers-349f0f4d3fd50b37.yaml
new file mode 100644
index 00000000..e24f4ff1
--- /dev/null
+++ b/releasenotes/notes/capping_nova_workers-349f0f4d3fd50b37.yaml
@@ -0,0 +1,7 @@
+---
+features:
+  - Capping the default value for the variables ``nova_wsgi_processes``,
+    ``nova_osapi_compute_workers``, ``nova_metadata_workers`` and
+    ``nova_conductor_workers`` to 16 when the user doesn't configure these
+    variables. Default value is half the number of vCPUs available on the
+    machine with a capping value of 16.
diff --git a/templates/nova.conf.j2 b/templates/nova.conf.j2
index c36a868a..7016a3e5 100644
--- a/templates/nova.conf.j2
+++ b/templates/nova.conf.j2
@@ -1,8 +1,5 @@
 # {{ ansible_managed }}
 
-{% set _api_threads = [ansible_processor_vcpus|default(2) // 2, nova_api_threads_max] | min %}
-{% set api_threads = _api_threads if _api_threads > 0 else 1 %}
-
 [DEFAULT]
 # Disable stderr logging
 use_stderr = False
@@ -39,7 +36,7 @@ key = {{ nova_console_ssl_key }}
 
 # Api's
 enabled_apis = {{ nova_enabled_apis }}
-osapi_compute_workers = {{ nova_osapi_compute_workers | default(api_threads) }}
+osapi_compute_workers = {{ nova_osapi_compute_workers | default(nova_api_threads) }}
 
 # Rpc all
 transport_url = rabbit://{% for host in nova_rabbitmq_servers.split(',') %}{{ nova_rabbitmq_userid }}:{{ nova_rabbitmq_password }}@{{ host }}:{{ nova_rabbitmq_port }}{% if not loop.last %},{% else %}/{{ nova_rabbitmq_vhost }}{% endif %}{% endfor %}
@@ -50,7 +47,7 @@ rpc_response_timeout = {{ nova_rpc_response_timeout }}
 # Metadata
 metadata_host = {{ nova_metadata_host }}
 metadata_port = {{ nova_metadata_port }}
-metadata_workers = {{ nova_metadata_workers | default(api_threads) }}
+metadata_workers = {{ nova_metadata_workers | default(nova_api_threads) }}
 
 # Network
 dhcp_domain = {{ nova_dhcp_domain }}
@@ -190,7 +187,7 @@ insecure = {{ keystone_service_adminuri_insecure | bool }}
 {% endif %}
 
 [conductor]
-workers = {{ nova_conductor_workers | default(api_threads) }}
+workers = {{ nova_conductor_workers | default(nova_api_threads) }}
 
 
 [keystone_authtoken]