Skip to content

Commit 090aaed

Browse files
committed
EXPERIMENT: Auto-tune PostgreSQL parameters
1 parent 92bb1cd commit 090aaed

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

src/roles/foreman/defaults/main.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,12 @@ foreman_database_name: foreman
66
foreman_database_user: foreman
77
foreman_database_host: localhost
88
foreman_database_port: 5432
9-
foreman_database_pool: 9
109
foreman_database_sslmode: disable
1110
foreman_database_sslrootcert:
1211

1312
foreman_url: "http://{{ ansible_facts['fqdn'] }}:3000"
1413

15-
# Puma threads calculation:
16-
# Max calculation is based on the default for MRI https://puma.io/puma6/#thread-pool
17-
# Min calculation is based on testing that showed that having the same value as the max led to
18-
# lower memory usage
19-
foreman_puma_threads_max: 5
2014
foreman_puma_threads_min: "{{ foreman_puma_threads_max }}"
21-
# Puma workers calculation:
22-
# CPU calculation is based on https://github.com/puma/puma/blob/master/docs/deployment.md#mri
23-
# Memory calculation is based on https://docs.gitlab.com/ee/install/requirements.html#puma-settings
24-
foreman_puma_workers: "{{ [32, ansible_facts['processor_nproc'] * 1.5, (ansible_facts['memtotal_mb'] / 1024) - 1.5] | min | int }}"
2515

2616
foreman_recurring_tasks_enabled: true
2717
foreman_recurring_tasks:

src/roles/postgresql/defaults/main.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ postgresql_data_dir: /var/lib/pgsql/data
99

1010
postgresql_admin_password: "CHANGEME"
1111

12-
postgresql_max_connections: 500
13-
postgresql_shared_buffers: 512MB
14-
postgresql_effective_cache_size: 1GB
12+
postgresql_max_connections: "{{ (postgresql_connection_count | int / 500) | round(0, 'ceil') | int * 500 }}"
13+
postgresql_shared_buffers_in_mb: "{{ (ansible_facts['memtotal_mb'] / 8 / 512) | round(0, 'ceil') | int * 512 }}"
14+
postgresql_shared_buffers: "{{ postgresql_shared_buffers_in_mb }}MB"
15+
postgresql_effective_cache_size: "{{ postgresql_shared_buffers_in_mb | int * 2 }}MB"

src/roles/pulp/defaults/main.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ pulp_api_image: "{{ pulp_container_image }}:{{ pulp_container_tag }}"
55
pulp_content_image: "{{ pulp_container_image }}:{{ pulp_container_tag }}"
66
pulp_worker_image: "{{ pulp_container_image }}:{{ pulp_container_tag }}"
77

8-
pulp_worker_count: "{{ [8, ansible_facts['processor_nproc']] | min }}"
9-
pulp_content_service_worker_count: "{{ (2 * ([8, ansible_facts['processor_nproc']] | min)) + 1 }}"
10-
pulp_api_service_worker_count: "{{ ([4, ansible_facts['processor_nproc']] | min) + 1 }}"
11-
128
pulp_volumes:
139
- /var/lib/pulp:/var/lib/pulp
1410

src/vars/defaults.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,32 @@ tuning_profile: development
55
flavor: katello
66
features: []
77
enabled_features: "{{ (flavor_features + features) }}"
8+
9+
# XXX: This number is the highest we've seen in our testing and needs to be explained
10+
candlepin_connection_count: 25
11+
12+
# Puma threads calculation:
13+
# Max calculation is based on the default for MRI https://puma.io/puma6/#thread-pool
14+
# Min calculation is based on testing that showed that having the same value as the max led to
15+
# lower memory usage
16+
foreman_puma_threads_max: 5
17+
# Puma workers calculation:
18+
# CPU calculation is based on https://github.com/puma/puma/blob/master/docs/deployment.md#mri
19+
# Memory calculation is based on https://docs.gitlab.com/ee/install/requirements.html#puma-settings
20+
foreman_puma_workers: "{{ [32, ansible_facts['processor_nproc'] * 1.5, (ansible_facts['memtotal_mb'] / 1024) - 1.5] | min | int }}"
21+
# Database pool calculation is based on https://community.theforeman.org/t/rails-connection-pool-size-optimizations/36675
22+
# The number 4 is for 4 threads that are spawned internally during the execution:
23+
# 1. Katello event daemon listener
24+
# 2. Katello event monitor poller
25+
# 3. Stomp listener (required by Katello)
26+
# 4. Puma server listener thread
27+
# This means for systems without Katello we can reduce the amount of the pool to foreman_puma_threads_max + 1
28+
foreman_database_pool: "{{ foreman_puma_threads_max | int + 4 }}"
29+
foreman_connection_count: "{{ foreman_puma_workers | int * foreman_database_pool | int }}"
30+
31+
pulp_worker_count: "{{ [8, ansible_facts['processor_nproc']] | min }}"
32+
pulp_content_service_worker_count: "{{ (2 * ([8, ansible_facts['processor_nproc']] | min)) + 1 }}"
33+
pulp_api_service_worker_count: "{{ ([4, ansible_facts['processor_nproc']] | min) + 1 }}"
34+
pulp_connection_count: "{{ pulp_worker_count | int + pulp_content_service_worker_count | int + pulp_api_service_worker_count | int }}"
35+
36+
postgresql_connection_count: "{{ candlepin_connection_count | int + foreman_connection_count | int + pulp_connection_count | int }}"

0 commit comments

Comments
 (0)