Last active
May 27, 2020 13:34
-
-
Save vozlt/44430943607ec72bedbd to your computer and use it in GitHub Desktop.
Nginx worker_cpu_affinity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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