Skip to content

Commit

Permalink
Round some worker counts up
Browse files Browse the repository at this point in the history
Fixes #9
Fixes spantaleev/matrix-docker-ansible-deploy#2953

This matches more closely what this logic does:
https://github.com/le0pard/pgtune/blob/master/src/features/configuration/configurationSlice.js

This better suits 1 CPU systems, on which dividing the number of CPUs by
2 yields "workers = 0.5", which may later be rounded by ` | int` to 0 on some systems.

Ending up with `0` causes a few problems:

- division by zero when calculating some other variables
- possibly setting workers = 0, which doesn't make sense

I personally couldn't reproduce the division by zero problem, as `0.5 | int` seems to be rounded up to `1` on my system.
Perhaps this behaves differently on other Ansible / Jinja2 versions or Python interpreter versions, etc.

Nevertheless, with this patch, it should be safe everywhere.
  • Loading branch information
spantaleev committed Oct 19, 2023
1 parent 63eed26 commit 69caab0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ devture_postgres_random_page_cost: "{{ '1.1' if devture_postgres_data_storage ==
devture_postgres_effective_io_concurrency: "{{ '200' if devture_postgres_data_storage == 'ssd' else '2' }}"
devture_postgres_max_worker_processes: "{{ ansible_processor_nproc }}"
devture_postgres_max_parallel_workers: "{{ ansible_processor_nproc }}"
devture_postgres_max_parallel_workers_per_gather: "{{ '4' if ansible_processor_nproc/2 > 4 else ansible_processor_nproc|int/2 }}"
devture_postgres_max_parallel_maintenance_workers: "{{ '4' if ansible_processor_nproc/2 > 4 else ansible_processor_nproc|int/2 }}"
devture_postgres_max_parallel_workers_per_gather: "{{ ('4' if ansible_processor_nproc/2 > 4 else ansible_processor_nproc|int/2) | round(0, 'ceil') | int }}"
devture_postgres_max_parallel_maintenance_workers: "{{ ('4' if ansible_processor_nproc/2 > 4 else ansible_processor_nproc|int/2) | round(0, 'ceil') | int }}"
devture_postgres_work_mem_raw: "{{ ((devture_postgres_memtotal_kb|int - devture_postgres_shared_buffers|int)/(devture_postgres_max_connections|int*3))/devture_postgres_max_parallel_workers_per_gather|int }}"
devture_postgres_work_mem: "{{ '64' if devture_postgres_work_mem_raw|int <= 64 else devture_postgres_work_mem_raw|int }}"
devture_postgres_huge_pages: "{{ 'off' if devture_postgres_memtotal_kb|int/1024/1024 < 32 else 'try' }}"
Expand Down

0 comments on commit 69caab0

Please sign in to comment.