| 1 | #! /usr/bin/env php |
|---|
| 2 | <?php |
|---|
| 3 | |
|---|
| 4 | // Runs a series of apache benchmarks. |
|---|
| 5 | |
|---|
| 6 | require_once(dirname($argv[0]) . "/utilities.php"); |
|---|
| 7 | |
|---|
| 8 | // URLs to benchmark |
|---|
| 9 | $benchmark_urls = array( |
|---|
| 10 | IA_URL . "arhiva", |
|---|
| 11 | IA_URL . "utilizator/domino?action=download&file=avatar&resize=L32x32", |
|---|
| 12 | IA_URL . "template/preoni-2006?action=download&file=hlogo.gif", |
|---|
| 13 | IA_URL . "utilizator/domino", |
|---|
| 14 | IA_URL . "changes", |
|---|
| 15 | IA_URL . "clasament-rating", |
|---|
| 16 | IA_URL . "monitor", |
|---|
| 17 | IA_URL . "monitor?first_entry=63425", |
|---|
| 18 | IA_URL . "monitor?task=fractii&round=arhiva&first_entry=3550", |
|---|
| 19 | IA_URL . "monitor?user=gabitzish1&first_entry=4550", |
|---|
| 20 | IA_URL . "monitor?first_entry=53425&round=arhiva&status=done&compiler=cpp", |
|---|
| 21 | IA_URL . "links", |
|---|
| 22 | IA_URL . "stiri", |
|---|
| 23 | IA_URL . "problema/adunare", |
|---|
| 24 | IA_URL . "preoni-2007/runda-1/9", |
|---|
| 25 | IA_URL . "unirea-2007/rezultate-9-10", |
|---|
| 26 | IA_URL . "plot/rating?user=gcosmin", |
|---|
| 27 | IA_URL . "utilizator/domino?action=stats", |
|---|
| 28 | IA_URL . "bogdan2412/cache-stress-test", |
|---|
| 29 | ); |
|---|
| 30 | |
|---|
| 31 | // parse options |
|---|
| 32 | // -n number_tests -c concurrency |
|---|
| 33 | $options = getopt("n:c:"); |
|---|
| 34 | $benchmark_n = getattr($options, 'n', 200); |
|---|
| 35 | $benchmark_c = getattr($options, 'c', 1); |
|---|
| 36 | |
|---|
| 37 | // benchmark command line |
|---|
| 38 | $benchmark_cmd = "ab -k -n {$benchmark_n} -c $benchmark_c %url% 2>&1"; |
|---|
| 39 | |
|---|
| 40 | // run benchmarks |
|---|
| 41 | log_print("Running {$benchmark_n} tests for each URL"); |
|---|
| 42 | foreach ($benchmark_urls as $url) { |
|---|
| 43 | $cmd = str_replace("%url%", escapeshellarg($url), $benchmark_cmd); |
|---|
| 44 | |
|---|
| 45 | $output = shell_exec($cmd); |
|---|
| 46 | |
|---|
| 47 | $ret = preg_match('/Requests per second:\s*([0-9.]+)\s/', $output, $match); |
|---|
| 48 | if (!$ret) { |
|---|
| 49 | log_var_dump($output); |
|---|
| 50 | log_error("Failed parsing ab output"); |
|---|
| 51 | } |
|---|
| 52 | $req = $match[1]; |
|---|
| 53 | $req_unit = 'reqs/s'; |
|---|
| 54 | |
|---|
| 55 | $ret = preg_match('/Transfer rate:\s*([0-9.]+)/', $output, $match); |
|---|
| 56 | if (!$ret) { |
|---|
| 57 | log_var_dump($output); |
|---|
| 58 | log_error("Failed parsing ab output"); |
|---|
| 59 | } |
|---|
| 60 | $trans = $match[1]; |
|---|
| 61 | $trans_unit = 'kb/s'; |
|---|
| 62 | |
|---|
| 63 | // pretty print |
|---|
| 64 | log_print("$url\t$req $req_unit\t$trans $trans_unit"); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | ?> |
|---|