Skip to content

Instantly share code, notes, and snippets.

@zauberstuhl
Created May 26, 2016 14:22
Show Gist options
  • Save zauberstuhl/4456c35d4a3b6e7c17de202cbfc8601f to your computer and use it in GitHub Desktop.
Save zauberstuhl/4456c35d4a3b6e7c17de202cbfc8601f to your computer and use it in GitHub Desktop.
Sidekiq dynamically adjustment through database load measuring
#!/bin/bash
MAX=12
SKMAX=50
SKMIN=12
DIR=/home/diaspora/diaspora
SSHCONFIG="-F $DIR/../.ssh/config yggdrasil"
CONFIG=$DIR/config/diaspora.yml
DATABASE=$DIR/config/database.yml
CONFIG_MD5=$(md5sum $CONFIG)
if [[ "$(whoami)" != "diaspora" ]];
then
echo "[C] You have to run this script as diaspora user"
exit 1
fi
LOAD=$(ssh $SSHCONFIG uptime |sed 's/ //g' |cut -d: -f5 |cut -d. -f1)
if [ $LOAD -gt $(($MAX-1)) ];
then
echo "[I] Invoke decreasing concurrency"
perl -pi -e "s/^(\s+concurrency: )\d+\$/\${1}$SKMIN/g" $CONFIG
perl -pi -e "s/^(\s+pool: )\d+\$/\${1}$SKMIN/g" $DATABASE
if [[ "$CONFIG_MD5" == "$(md5sum $CONFIG)" ]];
then
echo "[I] No restart required"
exit 0
fi
cd $DIR && eye restart sidekiq
else
echo "[I] Invoke increasing concurrency"
perl -pi -e "s/^(\s+concurrency: )\d+\$/\${1}$SKMAX/g" $CONFIG
perl -pi -e "s/^(\s+pool: )\d+\$/\${1}$SKMAX/g" $DATABASE
if [[ "$CONFIG_MD5" == "$(md5sum $CONFIG)" ]];
then
echo "[I] No restart required"
exit 0
fi
cd $DIR && eye restart sidekiq
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment