Skip to content

Instantly share code, notes, and snippets.

Created May 8, 2017 00:46
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 anonymous/4033da25d5e1ec8cb6fa85d60b05ba2a to your computer and use it in GitHub Desktop.
Save anonymous/4033da25d5e1ec8cb6fa85d60b05ba2a to your computer and use it in GitHub Desktop.
#!/usr/local/bin/php
<?php
shell_exec('ssh debian sudo service hhvm stop');
function parse_siege($data) {
preg_match("#(\d+\.\d+) trans/sec#",$data,$m);
$rps = $m[1];
preg_match("#Response time:\s*(\d+\.\d+) secs#",$data,$m);
$lat = $m[1];
preg_match("#Failed transactions:\s*(\d+)#",$data,$m);
$failed = $m[1];
return [$rps,$lat,$failed];
}
function benchmark($url, array $versions, $sec=60, array $conc=[5,20,50]) {
foreach($versions as $version) {
echo "Benchmarking PHP $version $url ...\n";
// Prepare server
if($version != 'hhvm') {
shell_exec("ssh debian sudo newphp $version");
shell_exec("ssh debian sudo cp /etc/nginx/php.conf /etc/nginx/backend.conf");
shell_exec("ssh debian sudo service nginx restart");
} else {
shell_exec("ssh debian sudo service php-fpm stop");
shell_exec("ssh debian sudo cp /etc/nginx/hhvm.conf /etc/nginx/backend.conf");
shell_exec("ssh debian sudo service hhvm start");
shell_exec("ssh debian sudo service nginx restart");
}
// Warm up
shell_exec("/usr/local/bin/siege -b -t1s -c4 --no-parser \"$url\" 2>&1 1> /dev/null");
$out = [];
foreach($conc as $c) {
echo "$c clients\n";
for($i=0; $i<3; $i++) {
sleep(2);
echo "/usr/local/bin/siege -b -t{$sec}s -c{$c} --no-parser \"$url\" 2>&1 1> /dev/null\n";
$out = shell_exec("/usr/local/bin/siege -b -t{$sec}s -c{$c} --no-parser \"$url\" 2>&1 1> /dev/null");
list($rps[$version][$c][$i], $lat[$version][$c][$i], $failed[$version][$c][$i]) = parse_siege($out);
}
echo max($rps[$version][$c]). " rps at ".min($lat[$version][$c])." (".max($failed[$version][$c]).")\n";;
}
}
return [$rps, $lat, $failed];
}
$urls = [
["http://wordpress/?p=1", [53,54,55,56,70,71,72,'72h','72hfdo']],
/*
["http://magento/index.php/sale.html", [53,54,55,56,7,'hhvm']],
["http://moodle/", [54,55,56,7]],
["http://cachet/", [54,55,56,7,'hhvm']],
["http://phpbb/viewtopic.php?f=2&t=1", [53,54,55,56,7,'hhvm']],
["http://bolt/page/this-is-my-first-post", [54,55,56,7,'hhvm']],
["http://drupal/node/1", [54,55,56,7,'hhvm']],
["http://traq/test/tickets/1", [53,54,55,56,7,'hhvm']],
["http://geeklog/index.php?topic=Geeklog", [53,54,55,56,7,'hhvm']],
["http://mediawiki/index.php/Main_Page", [53,54,55,56,7,'hhvm']],
["http://wordpress/?p=1", [53,54,55,56,7,'hhvm']],
["http://opencart/index.php?route=product/product&product_id=43", [53,54,55,56,7,'hhvm']],
["http://zencart/index.php?main_page=product_info&cPath=1_8&products_id=25", [53,54,55,56,7]],
*/
];
$conc = [10,20,40];
foreach($urls as $a) {
list($url,$vers) = $a;
list($rps, $lat, $failed) = benchmark($url, $vers, 30, $conc);
foreach($conc as $c) {
foreach($vers as $v) {
$results_rps[$url][$c][$v] = max($rps[$v][$c]);
$results_lat[$url][$c][$v] = 1000*max($lat[$v][$c]);
if(max($failed[$v][$c]) != 0) {
echo "$url with $v @ $c failed\n";
print_r($failed[$v][$c]);
}
}
}
}
foreach($results_rps as $url=>$cv) {
echo "$url\n";
foreach($cv as $c=>$v) {
echo "r/s @ $c\n";
echo "[".(implode(',',$v))."],\n";
echo "[".(implode(',',$results_lat[$url][$c]))."],\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment