Created
October 4, 2012 14:12
-
-
Save boutell/3833761 to your computer and use it in GitHub Desktop.
Check distribution of fastcgi processes over the hyperthreads and cores of your server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Are your fastcgi processes spread out evenly over the available hyperthreads on your server? | |
// This script will tell you. | |
// | |
// If your php-cgi process is not /usr/local/bin/php-cgi, tweak accordingly. | |
// | |
// In my experience they do tend to distribute pretty well over time, but see also | |
// assignhyperthreads.php. | |
// | |
// [email protected], @boutell, punkave.com | |
$pids = glob("/proc/*"); | |
$hyperthreadsTotal = count(preg_grep('/^processor/', file('/proc/cpuinfo'))); | |
echo("Total hyperthreads: $hyperthreadsTotal\n"); | |
for ($i = 0; ($i < $hyperthreadsTotal); $i++) | |
{ | |
$cpus[$i] = 0; | |
} | |
foreach ($pids as $pid) | |
{ | |
$pid = basename($pid); | |
if (preg_match('/^\d+$/', $pid)) | |
{ | |
$cmd = file_get_contents("/proc/$pid/cmdline"); | |
$elements = explode("\x00", $cmd); | |
if (count($elements)) | |
{ | |
if ($elements[0] === '/usr/local/bin/php-cgi') | |
{ | |
$stat = file_get_contents("/proc/$pid/stat"); | |
$columns = explode(' ', $stat); | |
$cpu = $columns[38]; | |
$cpus[$cpu]++; | |
$total++; | |
} | |
} | |
} | |
} | |
echo("Total fastcgi processes: $total\n"); | |
for ($i = 0; ($i < $hyperthreadsTotal); $i++) | |
{ | |
echo($cpus[$i] . "\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment