Skip to content

Instantly share code, notes, and snippets.

@akhy
Created July 20, 2017 09:15
Show Gist options
  • Save akhy/f949dd5fc099808716e09550eeab7b06 to your computer and use it in GitHub Desktop.
Save akhy/f949dd5fc099808716e09550eeab7b06 to your computer and use it in GitHub Desktop.
gunicorn workers config based on physical cpu
from sys import platform
if platform == "linux" or platform == "linux2":
from sh import grep, wc, cat
# cat /proc/cpuinfo | grep 'core id' | wc -l
cpu_count = wc(grep(cat('/proc/cpuinfo'), 'core id'), '-l')
elif platform == "darwin":
from sh import grep, sysctl, awk
# sysctl -a | grep machdep.cpu.core_count | awk '{print $2}'
cpu_count = awk(grep(sysctl('-a'), 'machdep.cpu.core_count'), '{print $2}')
if cpu_count:
globals()['workers'] = 2 * int(cpu_count) + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment