Skip to content

Instantly share code, notes, and snippets.

@holly
Last active January 30, 2021 15:50
Show Gist options
  • Save holly/3cb8099b342c8ce01b2805fd9a7627b2 to your computer and use it in GitHub Desktop.
Save holly/3cb8099b342c8ce01b2805fd9a7627b2 to your computer and use it in GitHub Desktop.
nginx worker_cpu_affinity generator (inspire from https://github.com/cubicdaiya/nwcagen/blob/master/nwcagen.go)
#!/bin/bash
cpu_num=$(nproc)
array=()
echo -n "worker_cpu_affinity "
if [ $cpu_num = 1 ]; then
echo "auto;"
exit
fi
for i in $(seq 1 $cpu_num); do
affinity=""
for j in $(seq 1 $cpu_num); do
if [ $i = $j ]; then
affinity+="1"
else
affinity+="0"
fi
done
array+=($affinity)
done
echo -n ${array[@]}
echo ";"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment