Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rickytato/df44f34259376d38ea31 to your computer and use it in GitHub Desktop.
Save rickytato/df44f34259376d38ea31 to your computer and use it in GitHub Desktop.
Normalize PHP-FPM CPU affinityAssumes 8 processors, #0 assigned to kernel+nginx
* * * * * root /usr/local/bin/normalize_cpu_affinity.sh
#!/bin/bash
# Normalize PHP-FPM CPU affinity
CPU=$((`grep -c processor /proc/cpuinfo` -1))
# PHP-FPM
for i in `ps auxw | grep php-fpm | grep -v grep | awk ' { print $2; } '`; do echo $i; taskset -pc 1-$CPU $i; done
# Nginx
for i in `ps auxw | grep nginx | grep -v grep | awk ' { print $2; } '`; do echo $i; taskset -pc 0 $i; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment