-
Notifications
You must be signed in to change notification settings - Fork 12
Added NUMA detection and configure mongodb to work correctly using NUMA #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Madias2222
wants to merge
4
commits into
itential:dev
Choose a base branch
from
Madias2222:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f7e20c7
Added NUMA detection and configure mongodb to work correctly
Madias2222 3853805
Remove redundant become directives in MongoDB config
Madias2222 2d8537a
Refactor systemd reload and restart tasks for mongod to streamline NU…
Madias2222 b76fcb0
Refactor NUMA configuration tasks for MongoDB to improve structure an…
Madias2222 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # Copyright (c) 2025, Itential, Inc | ||
| # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
| --- | ||
|
|
||
| - name: Detect NUMA nodes | ||
| ansible.builtin.shell: | ||
| cmd: | | ||
| if [ -d /sys/devices/system/node ]; then | ||
| ls -d /sys/devices/system/node/node[0-9]* 2>/dev/null | wc -l | ||
| else | ||
| echo 0 | ||
| fi | ||
| args: | ||
| executable: /bin/bash | ||
| register: mongodb_numa_nodes | ||
| changed_when: false | ||
|
|
||
| - name: Set NUMA enabled fact | ||
| ansible.builtin.set_fact: | ||
| mongodb_numa_enabled: "{{ (mongodb_numa_nodes.stdout | int) > 1 }}" | ||
|
|
||
| - name: Enable NUMA settings if multiple NUMA nodes detected | ||
| when: mongodb_numa_enabled | ||
| block: | ||
| - name: Ensure numactl is installed when NUMA is enabled | ||
| ansible.builtin.package: | ||
| name: numactl | ||
| state: present | ||
|
|
||
| - name: Discover numactl path | ||
| ansible.builtin.shell: | ||
| cmd: "command -v numactl || true" | ||
| args: | ||
| executable: /bin/bash | ||
| register: mongodb_numactl_path_result | ||
| changed_when: false | ||
| become: true | ||
|
|
||
| - name: Discover mongod path | ||
| ansible.builtin.shell: | ||
| cmd: "command -v mongod || true" | ||
| args: | ||
| executable: /bin/bash | ||
| register: mongodb_mongod_path_result | ||
| changed_when: false | ||
|
|
||
| - name: Set NUMA helper facts | ||
| ansible.builtin.set_fact: | ||
| mongodb_numactl_path: "{{ mongodb_numactl_path_result.stdout | default('', true) }}" | ||
| mongodb_mongod_path: "{{ mongodb_mongod_path_result.stdout | default('/usr/bin/mongod', true) }}" | ||
| mongodb_numactl_present: "{{ (mongodb_numactl_path_result.stdout | default('', true) | length) > 0 }}" | ||
|
|
||
| - name: Apply NUMA sysctl settings | ||
| ansible.posix.sysctl: | ||
| name: vm.zone_reclaim_mode | ||
| value: "{{ mongodb_vm_zone_reclaim_mode }}" | ||
| state: present | ||
| sysctl_file: "{{ mongodb_sysctl_file }}" | ||
| reload: true | ||
|
|
||
| - name: Disable kernel NUMA balancing | ||
| ansible.posix.sysctl: | ||
| name: kernel.numa_balancing | ||
| value: "0" | ||
| state: present | ||
| sysctl_file: "{{ mongodb_sysctl_file }}" | ||
| reload: true | ||
|
|
||
| - name: Ensure mongod systemd drop-in directory exists | ||
| ansible.builtin.file: | ||
| path: /etc/systemd/system/mongod.service.d | ||
| state: directory | ||
| mode: "0755" | ||
| when: mongodb_numactl_present | ||
|
|
||
| - name: Configure mongod to run with numactl interleave | ||
| ansible.builtin.copy: | ||
| dest: /etc/systemd/system/mongod.service.d/numa.conf | ||
| mode: "0644" | ||
| content: | | ||
| [Service] | ||
| ExecStart= | ||
| ExecStart={{ mongodb_numactl_path }} --interleave=all {{ mongodb_mongod_path }} --config {{ mongodb_conf_file }} | ||
| register: mongodb_numa_dropin | ||
| when: mongodb_numactl_present | ||
|
|
||
| - name: Reload systemd and restart mongod to apply NUMA settings | ||
| ansible.builtin.systemd: | ||
| name: mongod | ||
| state: restarted | ||
| daemon_reload: true | ||
| when: | ||
| - mongodb_numactl_present | ||
| - mongodb_numa_dropin is defined | ||
| - mongodb_numa_dropin.changed | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.