Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinstoller/be74065c3299ec88fdd27afb6414de2a to your computer and use it in GitHub Desktop.
Save justinstoller/be74065c3299ec88fdd27afb6414de2a to your computer and use it in GitHub Desktop.
#!/bin/bash
numProc=`cat /proc/cpuinfo | grep processor | wc -l`
megsMem=`cat /proc/meminfo | grep MemTotal | grep -Eo '[[:digit:]]+' | awk '{print int(($0 / 1000) +0.5)}'`
# JRuby 9k requires more space for codecaching
# and metaspace
if [[ $numProc -gt 6 ]]; then
codeCache=512
elif [[ $numProc -gt 12 ]]; then
codeCache=1024
else
codeCache=256
fi
metaSpace=$codeCache
nonHeap=$((codeCache + metaSpace))
# We'll want the same number of JRuby workers
# as processors
numWorkers=$numProc
# Recommendation is 512M per worker plus some
# more for the base application.
heap=$((((numProc + 1) * 1000) / 2))
totalMem=$((heap + nonHeap))
if [[ $totalMem -gt $megsMem ]]; then
echo "There is not enough memory for the number of CPUs"
exit 1
fi
server_conf="/etc/puppetlabs/puppetserver/conf.d/puppetserver.conf"
sysconfig="/etc/sysconfig/puppetserver"
if [[ `grep "#max-active-instances" $server_conf` ]]; then
sed -i "s/#max-active-instances: 1/max-active-instances: $numWorkers/" $server_conf
else
echo "Not updating max-active-instances because of existing value"
fi
if [[ `grep "Xms2g" $sysconfig` ]] &&
[[ `grep "Xmx2g" $sysconfig` ]]; then
sed -i "s/Xms2g/Xms${heap}m/" $sysconfig
sed -i "s/Xmx2g/Xmx${heap}m/" $sysconfig
else
echo "Not updating heap settings because of existing values"
fi
if [[ ! `grep "ReservedCodeCacheSize" $sysconfig` ]] ||
[[ ! `grep "MaxMetaspaceSize" $sysconfig` ]] ; then
sed -i "s/JAVA_ARGS=\"/JAVA_ARGS=\"-XX:ReservedCodeCacheSize=$codeCache /" $sysconfig
sed -i "s/JAVA_ARGS=\"/JAVA_ARGS=\"-XX:MaxMetaspaceSize=size=$metaSpace /" $sysconfig
else
echo "Not updating ReservedCodeCacheSize or MaxMetaspaceSize because of existing values"
fi
systemctl restart puppetserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment