Avoid sudo in tune-system.sh unless requested by the user (#4556)
This commit is contained in:
parent
5c98c1d306
commit
d26fd27bf9
|
@ -61,6 +61,7 @@ local|tar)
|
||||||
./fetch-perf-libs.sh
|
./fetch-perf-libs.sh
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
source ./target/perf-libs/env.sh
|
source ./target/perf-libs/env.sh
|
||||||
|
SUDO_OK=1 source scripts/tune-system.sh
|
||||||
|
|
||||||
(
|
(
|
||||||
sudo scripts/oom-monitor.sh
|
sudo scripts/oom-monitor.sh
|
||||||
|
|
|
@ -6,35 +6,46 @@
|
||||||
# shellcheck source=scripts/ulimit-n.sh
|
# shellcheck source=scripts/ulimit-n.sh
|
||||||
source "$(dirname "${BASH_SOURCE[0]}")"/ulimit-n.sh
|
source "$(dirname "${BASH_SOURCE[0]}")"/ulimit-n.sh
|
||||||
|
|
||||||
|
sysctl_write() {
|
||||||
|
declare name=$1
|
||||||
|
declare new_value=$2
|
||||||
|
|
||||||
|
# Test the existence of the sysctl before trying to set it
|
||||||
|
sysctl "$name" 2>/dev/null 1>/dev/null || return
|
||||||
|
|
||||||
|
declare current_value
|
||||||
|
current_value=$(sysctl -n "$name")
|
||||||
|
[[ $current_value != "$new_value" ]] || return
|
||||||
|
|
||||||
|
declare cmd="sysctl -w $name=$new_value"
|
||||||
|
if [[ -n $SUDO_OK ]]; then
|
||||||
|
cmd="sudo $cmd"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$ $cmd"
|
||||||
|
$cmd
|
||||||
|
|
||||||
|
# Some versions of sysctl exit with 0 on permission denied errors
|
||||||
|
current_value=$(sysctl -n "$name")
|
||||||
|
if [[ $current_value != "$new_value" ]]; then
|
||||||
|
echo "==> Failed to set $name. Try running: \"SUDO_OK=1 source ${BASH_SOURCE[0]}\""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case $(uname) in
|
||||||
|
Linux)
|
||||||
# Reference: https://medium.com/@CameronSparr/increase-os-udp-buffers-to-improve-performance-51d167bb1360
|
# Reference: https://medium.com/@CameronSparr/increase-os-udp-buffers-to-improve-performance-51d167bb1360
|
||||||
if [[ $(uname) = Linux ]]; then
|
sysctl_write net.core.rmem_max 161061273
|
||||||
(
|
sysctl_write net.core.rmem_default 161061273
|
||||||
set -x +e
|
sysctl_write net.core.wmem_max 161061273
|
||||||
# test the existence of the sysctls before trying to set them
|
sysctl_write net.core.wmem_default 161061273
|
||||||
# go ahead and return true and don't exit if these calls fail
|
;;
|
||||||
sysctl net.core.rmem_max 2>/dev/null 1>/dev/null &&
|
|
||||||
sudo sysctl -w net.core.rmem_max=161061273 1>/dev/null 2>/dev/null
|
|
||||||
|
|
||||||
sysctl net.core.rmem_default 2>/dev/null 1>/dev/null &&
|
|
||||||
sudo sysctl -w net.core.rmem_default=161061273 1>/dev/null 2>/dev/null
|
|
||||||
|
|
||||||
sysctl net.core.wmem_max 2>/dev/null 1>/dev/null &&
|
|
||||||
sudo sysctl -w net.core.wmem_max=161061273 1>/dev/null 2>/dev/null
|
|
||||||
|
|
||||||
sysctl net.core.wmem_default 2>/dev/null 1>/dev/null &&
|
|
||||||
sudo sysctl -w net.core.wmem_default=161061273 1>/dev/null 2>/dev/null
|
|
||||||
) || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $(uname) = Darwin ]]; then
|
|
||||||
(
|
|
||||||
if [[ $(sysctl net.inet.udp.maxdgram | cut -d\ -f2) != 65535 ]]; then
|
|
||||||
echo "Adjusting maxdgram to allow for large UDP packets, see BLOB_SIZE in src/packet.rs:"
|
|
||||||
set -x
|
|
||||||
sudo sysctl net.inet.udp.maxdgram=65535
|
|
||||||
fi
|
|
||||||
)
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
Darwin)
|
||||||
|
# Adjusting maxdgram to allow for large UDP packets, see BLOB_SIZE in core/src/packet.rs
|
||||||
|
sysctl_write net.inet.udp.maxdgram 65535
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue