Created
June 11, 2015 05:29
-
-
Save kamermans/c2ddb4529a68c1f4692f to your computer and use it in GitHub Desktop.
Set PHP-FPM pool workers CPU affinity so each worker gets one CPU core
This file contains 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 | |
# Set PHP-FPM pool workers CPU affinity so each worker gets one CPU core | |
# Note that FPM recycles threads, so you'll need to run this on cron periodically | |
# Author: Steve Kamerman | |
CPUS=$(grep -c CPU /proc/cpuinfo) | |
FPM_PIDS=$(ps auxw | grep php-fpm | grep pool | awk '{ print $2; }') | |
if [ "$FPM_PIDS" = "" ]; then | |
echo "PHP-FPM is not running" | |
fi | |
typeset -i i | |
let i=0 | |
for PID in $FPM_PIDS; do | |
THIS_CPU=$(echo "$i % $CPUS" | bc) | |
taskset -pc $THIS_CPU $PID | |
let i++ | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment