Skip to content

Instantly share code, notes, and snippets.

@vozlt
Last active May 27, 2020 13:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vozlt/44430943607ec72bedbd to your computer and use it in GitHub Desktop.
Save vozlt/44430943607ec72bedbd to your computer and use it in GitHub Desktop.
Nginx worker_cpu_affinity
#!/bin/bash
#
# @file: nginx-affinity.sh
# @brief:
# @author: YoungJoo.Kim <http://vozlt.com>
# @version:
# @date:
#
# Linux only.
# Nginx worker_cpu_affinity
# http://wiki.nginx.org/CoreModule
n=$(awk '/^processor/{n=$3} END{print n}' /proc/cpuinfo)
aff=$(printf "0%0${n}d" 0)
printf "worker_processes %d;\n" $((n+1))
[ $n -eq 0 ] && exit;
printf "worker_cpu_affinity "
for ((a=0; a <= n; a++))
do
poss=$((n - a))
pose=$((n - poss))
if [ $pose -eq 0 ]; then
printf "%0${poss}d1" 0
elif [ $poss -eq 0 ]; then
[ $poss -eq 0 ] && printf "1%0${pose}d" 0
else
[ $pose -ne 0 ] && printf "%0${poss}d1%0${pose}d" 0 0
fi
[ $n != $a ] && echo -n " " || echo ";";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment