Skip to content

Instantly share code, notes, and snippets.

@danbst
Last active October 27, 2016 17:55
Show Gist options
  • Save danbst/58150662994eda45443c3c9a9fbf4172 to your computer and use it in GitHub Desktop.
Save danbst/58150662994eda45443c3c9a9fbf4172 to your computer and use it in GitHub Desktop.
{ pkgs, config, ...}: {
boot.kernel.sysctl."net.core.rps_sock_flow_entries" = "32768";
networking.usePredictableInterfaceNames = false; # we want eth0
system.activationScripts.network_debloat = {
text = ''
interface=eth0
${pkgs.iproute}/bin/tc qdisc replace dev "$interface" root fq_codel
${pkgs.iproute}/bin/tc qdisc replace dev "$interface" handle 1 root mq
I=0
for q in $(ls -d /sys/class/net/"$interface"/queues/rx-*); do
echo $((I++)) > /dev/null
${pkgs.iproute}/bin/tc qdisc add dev "$interface" parent 1:$(printf "%x" $I) fq_codel
done
(
${pkgs.ethtool}/bin/ethtool -K "$interface" tso off
${pkgs.ethtool}/bin/ethtool -K "$interface" gso off
${pkgs.ethtool}/bin/ethtool -K "$interface" ufo off
# Presently unknown if gro/lro affect latency much
${pkgs.ethtool}/bin/ethtool -K "$interface" gro off
${pkgs.ethtool}/bin/ethtool -K "$interface" lro off
) 2>/dev/null
npr=$(getconf _NPROCESSORS_ONLN)
for q in $(ls -d /sys/class/net/"$interface"/queues/rx-*); do
echo ${config.boot.kernel.sysctl."net.core.rps_sock_flow_entries"} > $q/rps_flow_cnt
if [[ "$npr" == "2" ]]; then
echo 3 > $q/rps_cpus
elif [[ "$npr" -gt 3 ]]; then
echo 15 > $q/rps_cpus
fi
done
'';
deps = [];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment