From e739164b55226ff1a91c9366b6ebc550b7f7a4ff Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Thu, 30 Jan 2020 11:39:22 -0500 Subject: [PATCH] ara_api role: Default gunicorn worker count based on CPU cores The recommended default formula as per gunicorn docs is: (2 x $num_cores) + 1 Change-Id: I37ac2051f5b17fdce283e486dfcd5c68d9eacfd0 --- roles/ara_api/defaults/main.yaml | 4 ++++ roles/ara_api/templates/ara-api.service.j2 | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/roles/ara_api/defaults/main.yaml b/roles/ara_api/defaults/main.yaml index 4c0f3b06..077387ea 100644 --- a/roles/ara_api/defaults/main.yaml +++ b/roles/ara_api/defaults/main.yaml @@ -83,6 +83,10 @@ ara_api_wsgi_server: null # "ara_api_cors_origin_whitelist". ara_api_wsgi_bind: "127.0.0.1:8000" +# Amount of worker processes for the wsgi server +# Recommended default formula by gunicorn: https://docs.gunicorn.org/en/stable/design.html#how-many-workers +ara_api_wsgi_workers: "{{ ansible_processor_count * ansible_processor_cores * ansible_processor_threads_per_core * 2 + 1 }}" + # When using a frontend server, the domain or address it will be listening on ara_api_fqdn: "{{ ansible_default_ipv4['address'] | default(ansible_default_ipv6['address']) }}" diff --git a/roles/ara_api/templates/ara-api.service.j2 b/roles/ara_api/templates/ara-api.service.j2 index edb8e73e..84937f09 100644 --- a/roles/ara_api/templates/ara-api.service.j2 +++ b/roles/ara_api/templates/ara-api.service.j2 @@ -8,9 +8,9 @@ RuntimeDirectory=ara-api WorkingDirectory={{ ara_api_root_dir }} Environment=ARA_SETTINGS={{ ara_api_settings }} {% if ara_api_venv %} -ExecStart={{ ara_api_venv_path }}/bin/gunicorn --workers=4 --bind {{ ara_api_wsgi_bind }} {{ _ara_api_wsgi_application | default('ara.server.wsgi') }} +ExecStart={{ ara_api_venv_path }}/bin/gunicorn --workers={{ ara_api_wsgi_workers }} --bind {{ ara_api_wsgi_bind }} {{ _ara_api_wsgi_application | default('ara.server.wsgi') }} {% else %} -ExecStart=gunicorn --workers=4 --bind {{ ara_api_wsgi_bind }} {{ _ara_api_wsgi_application | default('ara.server.wsgi') }} +ExecStart=gunicorn --workers={{ ara_api_wsgi_workers }} --bind {{ ara_api_wsgi_bind }} {{ _ara_api_wsgi_application | default('ara.server.wsgi') }} {% endif %} ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID