Skip to content

Instantly share code, notes, and snippets.

@cloudnull
Last active January 27, 2025 15:10
Show Gist options
  • Save cloudnull/45b8d52d24888988b3225c027141b3c2 to your computer and use it in GitHub Desktop.
Save cloudnull/45b8d52d24888988b3225c027141b3c2 to your computer and use it in GitHub Desktop.
Set the NIC Hardware Queue RX and TX to more appropriate values
#!/usr/bin/env bash
set -e
# NOTE(cloudnull): This script is intended to be run on a system that has
# multiple physical network interfaces. The script will
# disable the hardware offload for the interfaces and set
# the RX and TX queue sizes to 90% of the maximum value
# to avoid packet loss.
#
# This script was written because the default values for
# the RX and TX queue sizes are often too low practical
# applications and has been observed to cause packet loss
# in some cases, when the system is under heavy load.
function ethernetDevs () {
# Returns all physical devices
ip -details -json link show | jq -r '.[] |
if .linkinfo.info_kind // .link_type == "loopback" or (.ifname | test("idrac+")) then
empty
else
.ifname
end
'
}
function functionSetMax () {
# The RX value is set to 90% of the max value to avoid packet loss
ethtool -G $1 rx $(ethtool --json -g $1 | jq '.[0] | ."rx-max" * .9 | round')
# The TX value is set to the max value
ethtool -G $1 tx $(ethtool --json -g $1 | jq '.[0] | ."tx-max"')
}
function functionHWTCOffloadOff () {
ethtool -K $1 hw-tc-offload off
}
jq --version || (echo "jq is not installed. Attempting to install jq" && apt update && apt -y install jq)
ethernetDevs | while read -r dev; do
echo "Setting queue max $dev"
functionSetMax $dev
echo "Disabling hw tc offload $dev"
functionHWTCOffloadOff $dev
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment