|
| 1 | +#!/bin/sh |
| 2 | +# Set a machine into benchmarking mode. |
| 3 | +# |
| 4 | +# For native Linux, and Intel-only for now (AMD has a different way of disabling turbo) |
| 5 | +# |
| 6 | +# References: https://llvm.org/docs/Benchmarking.html |
| 7 | + |
| 8 | +declare -a packages=( |
| 9 | + "cpupower" "tuned" "ss" "turbostat" "lscpu" "lspci" "ip" "ethtool" "jq" "nginx" "hitch" "stunnel" "iperf3" "nuttcp" "httping" "git" "hyperfine" |
| 10 | +) |
| 11 | + |
| 12 | +install_packages() |
| 13 | +{ |
| 14 | + # This is for Fedora 42, adapt for your own OS |
| 15 | + sudo dnf install "${packages[@]}" |
| 16 | +} |
| 17 | + |
| 18 | +stop_services() |
| 19 | +{ |
| 20 | + sudo cp /lib/systemd/system/rescue.target /lib/systemd/system/benchmark.target |
| 21 | + sudo systemctl add-wants benchmark.target sshd.service |
| 22 | + sudo systemctl isolate benchmark.target |
| 23 | + sudo systemctl list-units --state=running |
| 24 | +} |
| 25 | + |
| 26 | +start_services() |
| 27 | +{ |
| 28 | + sudo systemctl isolate multi-user.target |
| 29 | +} |
| 30 | + |
| 31 | +set_cpu() |
| 32 | +{ |
| 33 | + # Prevent frequency-scaling |
| 34 | + sudo cpupower frequency-set -g performance |
| 35 | + |
| 36 | + # Prevent entering deep C-states to reduce latency and avoid menu governor bugs (there was one recently) |
| 37 | + # Although if we completely disable C1 then we are going to hit RAPL power limits immediately, |
| 38 | + # which results in a 30% perf hit on single-stream iperf |
| 39 | + # Disable just deeper C states, which avoids the big perf hit (although now we're exposed to menu governor bugs) |
| 40 | + sudo cpupower idle-set -D 2 |
| 41 | + |
| 42 | + # Disable Turbo Boost for more stable measurements |
| 43 | + # cpupower set --turbo-boost 0 doesn't work when the driver is intel_pstate instead of cpufreq |
| 44 | + sudo sh -c 'echo 1 >/sys/devices/system/cpu/intel_pstate/no_turbo' |
| 45 | + |
| 46 | + sudo cpupower -c all set --perf-bias 0 |
| 47 | + |
| 48 | + # Bring system into a consistent state |
| 49 | + # TODO: switch and reboot between the two |
| 50 | + #sudo tuned-adm profile network-latency |
| 51 | + |
| 52 | + sudo tuned-adm profile network-throughput |
| 53 | + |
| 54 | + # we could use tuned-adm verify, but there is a bug where it tries to read non-existent hung_task_timeout_secs |
| 55 | +} |
| 56 | + |
| 57 | +describe() |
| 58 | +{ |
| 59 | + # Check all the settings we've changed above |
| 60 | + |
| 61 | + # List running processes |
| 62 | + set -x |
| 63 | + sudo systemctl list-units --state=running |
| 64 | + LIBPROC_HIDE_KERNEL=1 ps -ejH |
| 65 | + |
| 66 | + sudo cpupower -c all frequency-info |
| 67 | + sudo cpupower -c all idle-info |
| 68 | + sudo cpupower -c all info |
| 69 | + sudo cat /sys/devices/system/cpu/intel_pstate/no_turbo |
| 70 | + sudo tuned-adm profile_info |
| 71 | + sudo ss -neopatium |
| 72 | + |
| 73 | + lscpu |
| 74 | + sudo turbostat true |
| 75 | + sudo lspci -k |
| 76 | + sudo ip a |
| 77 | + |
| 78 | + for P in /sys/class/net/*; do |
| 79 | + IFACE=$(basename "${P}") |
| 80 | + sudo ethtool "${IFACE}" |
| 81 | + sudo ethtool -k "${IFACE}" |
| 82 | + done |
| 83 | + |
| 84 | + sudo sos report --batch |
| 85 | + |
| 86 | + set +x |
| 87 | +} |
| 88 | + |
| 89 | +open_ports() |
| 90 | +{ |
| 91 | + # iperf3, nuttcp |
| 92 | + for P in 5201 5000 5001 5101 5102 5103 5104; do |
| 93 | + sudo firewall-cmd --add-port "${P}/tcp" |
| 94 | + done |
| 95 | +} |
| 96 | + |
| 97 | +iperf3_server() |
| 98 | +{ |
| 99 | + iperf3 -s |
| 100 | +} |
| 101 | + |
| 102 | +iperf3_client() |
| 103 | +{ |
| 104 | + # TODO: autodetect IP |
| 105 | + iperf3 --json --logfile iperf3.json -c 10.70.58.43 |
| 106 | + iperf3 --json --logfile iperf3_2.json -c 10.70.58.43 -P2 |
| 107 | + iperf3 --json --logfile iperf3_4.json -c 10.70.58.43 -P4 |
| 108 | +} |
| 109 | + |
| 110 | + |
0 commit comments