Skip to content

Instantly share code, notes, and snippets.

@tobert
Created August 1, 2011 18:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobert/1118667 to your computer and use it in GitHub Desktop.
Save tobert/1118667 to your computer and use it in GitHub Desktop.
Improve ruby's performance by locking to a single CPU
#!/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