Created
August 1, 2011 18:11
-
-
Save tobert/1118667 to your computer and use it in GitHub Desktop.
Improve ruby's performance by locking to a single CPU
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 | |
# Ruby's GIL is a liability when actually doing CPU work | |
# on a large SMP machine, doubly so on NUMA. This works around it. | |
# Ruby processes are locked onto a single core + its HT sibling | |
# on intel machines, 2 cores on AMD. Ideally this would lock to | |
# one core on non-HT processors, but all of mine are HT so it WFM. | |
max_cpu=$(cat /proc/cpuinfo |awk -F ': ' '/processor/{print $2}' |tail -n 1) | |
i=0 | |
for proc in $(ps -o pid= -C ruby) | |
do | |
taskset -cp $i,$(($i+1)) $proc | |
let i='i+2' | |
if [ $i -gt $max_cpu ] ; then | |
i=0 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment