Skip to content

Commit 630b38f

Browse files
authored
fix: Add oneshot service for queue max handling (#692)
Implement the service one shot for automatically setting the queue max. Related Issue: https://rackspace.atlassian.net/browse/OSPC-832 Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
1 parent 15642f4 commit 630b38f

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description = Oneshot service for queue max
3+
After = network-online.target
4+
5+
[Service]
6+
Type = oneshot
7+
ExecStart = /usr/local/bin/queue_max.sh
8+
9+
[Install]
10+
WantedBy = multi-user.target
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
# shellcheck disable=SC2086,SC2046
3+
set -e
4+
5+
# NOTE(cloudnull): This script is intended to be run on a system that has
6+
# multiple physical network interfaces. The script will
7+
# disable the hardware offload for the interfaces and set
8+
# the RX and TX queue sizes to 90% of the maximum value
9+
# to avoid packet loss.
10+
#
11+
# This script was written because the default values for
12+
# the RX and TX queue sizes are often too low practical
13+
# applications and has been observed to cause packet loss
14+
# in some cases, when the system is under heavy load.
15+
16+
function ethernetDevs () {
17+
# Returns all physical devices
18+
ip -details -json link show | jq -r '.[] |
19+
if .linkinfo.info_kind // .link_type == "loopback" or (.ifname | test("idrac+")) then
20+
empty
21+
else
22+
.ifname
23+
end
24+
'
25+
}
26+
27+
function functionSetMax () {
28+
echo "Setting queue max $dev"
29+
# The RX value is set to 90% of the max value to avoid packet loss
30+
ethtool -G $1 rx $(ethtool --json -g $1 | jq '.[0] | ."rx-max" * .9 | round')
31+
# The TX value is set to the max value
32+
ethtool -G $1 tx $(ethtool --json -g $1 | jq '.[0] | ."tx-max"')
33+
}
34+
35+
function functionHWTCOffloadOff () {
36+
if [[ $(ethtool --json -k $1 | jq '.[] | ."hw-tc-offload"') != "null" ]]; then
37+
echo "Disabling hw tc offload $dev"
38+
ethtool -K $1 hw-tc-offload off
39+
fi
40+
}
41+
42+
jq --version || (echo "jq is not installed. Attempting to install jq" && apt update && apt -y install jq)
43+
44+
ethernetDevs | while read -r dev; do
45+
functionSetMax $dev
46+
functionHWTCOffloadOff $dev
47+
done

ansible/roles/host_setup/handlers/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,9 @@
3232
- name: Systemd daemon reload
3333
ansible.builtin.systemd:
3434
daemon_reload: true
35+
36+
- name: Restart sysstat
37+
ansible.builtin.systemd:
38+
name: "queue_max.service"
39+
state: "restarted"
40+
enabled: true

ansible/roles/host_setup/tasks/configure_hosts.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,16 @@
6565
ansible.builtin.include_tasks: sysstat.yml
6666
when:
6767
- host_sysstat_enabled | bool
68+
69+
- name: Create queue max script
70+
ansible.builtin.copy:
71+
src: queue_max.sh
72+
dest: /usr/local/bin/queue_max.sh
73+
mode: "0755"
74+
75+
- name: Create queue max service
76+
ansible.builtin.copy:
77+
src: queue_max.service
78+
dest: /etc/systemd/system/queue_max.service
79+
mode: "0644"
80+
notify: Load and start queue_max service

0 commit comments

Comments
 (0)