Skip to content

Commit f34f6cb

Browse files
hunleydCopilot
andauthored
feat(tuned): ensure CPUs are giving it their all (#2069)
* feat(tuned): ensure CPUs are giving it their all This commit enhances the custom `tuned` profile for PostgreSQL by forcing the CPU into a maximum performance state. These changes are critical for maintaining consistent low-latency database performance. Key Changes and Benefits: - CPU Governor & Energy Bias: Switched to 'performance' mode. This prevents the kernel from scaling down CPU frequencies during periods of lower activity, eliminating the "ramp-up" latency when a burst of queries arrives. - Min Performance Percentage: Fixed at 100% to ensure the processor stays at its maximum base frequency, reducing jitter in query execution times. * Update ansible/tasks/setup-tuned.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update ansible/tasks/setup-tuned.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: bump AMI version * fix(tuned): handle both old and current tuned versions * fix(tuned): address Sam's concerns --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 950efd9 commit f34f6cb

2 files changed

Lines changed: 60 additions & 11 deletions

File tree

ansible/tasks/setup-tuned.yml

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,89 @@
1616
group: 'root'
1717
mode: '0755'
1818
owner: 'root'
19-
path: '/etc/tuned/postgresql'
19+
path: '/etc/tuned/profiles/postgresql'
2020
state: 'directory'
2121
become: true
2222

23+
- name: Create a profile symlink for older tuned versions
24+
ansible.builtin.file:
25+
force: true
26+
group: 'root'
27+
mode: '0755'
28+
owner: 'root'
29+
path: '/etc/tuned/postgresql'
30+
src: '/etc/tuned/profiles/postgresql'
31+
state: 'link'
32+
become: true
33+
2334
- name: Create a tuned profile
35+
become: true
2436
community.general.ini_file:
2537
create: true
2638
group: 'root'
2739
mode: '0644'
2840
no_extra_spaces: true
2941
option: 'summary'
30-
path: '/etc/tuned/postgresql/tuned.conf'
42+
path: '/etc/tuned/profiles/postgresql/tuned.conf'
3143
section: 'main'
3244
state: 'present'
3345
value: 'Tuned profile for PostgreSQL'
34-
become: true
3546

36-
- name: Disable Transparent Huge Pages (THP)
47+
- name: tuned - Disable Transparent Huge Pages (THP)
48+
become: true
3749
community.general.ini_file:
3850
create: true
3951
group: 'root'
4052
mode: '0644'
4153
no_extra_spaces: true
4254
option: "{{ thp_item['option'] }}"
43-
path: '/etc/tuned/postgresql/tuned.conf'
55+
path: '/etc/tuned/profiles/postgresql/tuned.conf'
4456
section: "{{ thp_item['section'] }}"
4557
state: 'present'
4658
value: "{{ thp_item['value'] }}"
47-
become: true
4859
loop:
49-
- { section: 'bootloader', option: 'cmdline', value: 'transparent_hugepage=never' }
50-
- { section: 'vm', option: 'transparent_hugepages', value: 'never' }
60+
- { section: 'bootloader', option: 'cmdline', value: 'transparent_hugepage=never' }
61+
- { section: 'vm', option: 'transparent_hugepages', value: 'never' }
5162
loop_control:
5263
loop_var: 'thp_item'
5364

65+
- name: tuned - Configure all CPUs for maximum performance
66+
become: true
67+
community.general.ini_file:
68+
create: true
69+
group: 'root'
70+
mode: '0644'
71+
no_extra_spaces: true
72+
option: "{{ cpu_item['option'] }}"
73+
path: '/etc/tuned/profiles/postgresql/tuned.conf'
74+
section: "{{ cpu_item['section'] }}"
75+
state: 'present'
76+
value: "{{ cpu_item['value'] }}"
77+
loop:
78+
- { section: 'cpu', option: 'governor', value: 'performance' }
79+
loop_control:
80+
loop_var: 'cpu_item'
81+
82+
- name: tuned - Configure Intel CPUs for maximum performance
83+
become: true
84+
community.general.ini_file:
85+
create: true
86+
group: 'root'
87+
mode: '0644'
88+
no_extra_spaces: true
89+
option: "{{ cpu_item['option'] }}"
90+
path: '/etc/tuned/profiles/postgresql/tuned.conf'
91+
section: "{{ cpu_item['section'] }}"
92+
state: 'present'
93+
value: "{{ cpu_item['value'] }}"
94+
loop:
95+
- { section: 'cpu', option: 'energy_perf_bias', value: 'performance' }
96+
- { section: 'cpu', option: 'min_perf_pct', value: '100' }
97+
loop_control:
98+
loop_var: 'cpu_item'
99+
when:
100+
- ansible_facts['processor'][0] is search("GenuineIntel", ignorecase=True)
101+
54102
- name: Activate the tuned service
55103
ansible.builtin.systemd_service:
56104
daemon_reload: true
@@ -63,3 +111,4 @@
63111
ansible.builtin.command:
64112
cmd: tuned-adm profile postgresql
65113
become: true
114+
changed_when: false

ansible/vars.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ postgres_major:
1010

1111
# Full version strings for each major version
1212
postgres_release:
13-
postgresorioledb-17: "17.6.0.047-orioledb"
14-
postgres17: "17.6.1.090"
15-
postgres15: "15.14.1.090"
13+
postgresorioledb-17: "17.6.0.048-orioledb"
14+
postgres17: "17.6.1.091"
15+
postgres15: "15.14.1.091"
1616

1717
# Non Postgres Extensions
1818
pgbouncer_release: 1.25.1

0 commit comments

Comments
 (0)