Skip to content

Instantly share code, notes, and snippets.

@caiosba
Created January 27, 2014 04:50
Show Gist options
  • Save caiosba/8643452 to your computer and use it in GitHub Desktop.
Save caiosba/8643452 to your computer and use it in GitHub Desktop.
Shell script to check which module(s) (or group of them) are responsible for high CPU load
#!/bin/bash
# This script disables the Drupal modules one by one and checks CPU load
# after disabling each. Please run it from the Drupal root. Set the URL below.
url='http://localhost/drupal'
# Check CPU load on the last minute
function cpuload {
uptime | sed 's/.*load average/CPU load on the last minute/g' | sed 's/,.*//g'
}
# Access the page 20 times and check the cpu load
function bulk_access {
cpuload
for i in {1..20}
do
wget -q $url -O /dev/null &
done
sleep 30
cpuload
# Number of on-going requests... for debugging only
n=$(ps aux | grep wget | grep -v grep | wc -l)
# Kill remaining requests
killall -9 wget 2>/dev/null
}
# Make a first check before disabling any module
n=$(drush pm-list --type=Module --no-core --status=enabled --pipe | wc -l)
echo "CPU load with all modules $n enabled"
bulk_access
sleep 30
# Iterate through each enabled, no-core module
for module in $(drush pm-list --type=Module --no-core --status=enabled --pipe)
do
echo '----------------------------------------------------------------------------------------------------'
echo "Checking module $module"
# Disable this module and its dependencies
drush dis $module -y
# Make one request just to rebuild Drupal cache
wget -q $url -O /dev/null
# Wait a little, just to let the CPU relax
sleep 30
bulk_access
# Re-enable the module and its dependencies
dependencies=$(drush pmi $module | grep 'Required by' -A 1000 | sed 's/.*://g' | sed ':a;N;$!ba;s/\s\+/ /g' | sed 's/,//g' | sed 's/^ //g')
drush en $module $dependencies -y
# Make one request just to rebuild cache
wget -q $url -O /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment