From 07d3f44867246a9f12b5f8c624ac0d46f77ff808 Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 3 Dec 2019 23:15:18 +0100 Subject: [PATCH] Add composer.json; fix typos in comments; remove unused code --- .editorconfig | 9 +++++++++ .gitattributes | 2 ++ README_ezab.md | 6 +++--- README_ezmyreplay.md | 8 ++++---- abrunner.php | 32 +++++++++++++++++++++----------- composer.json | 11 +++++++++++ ezab.php | 41 +++++++++++++++++++++++------------------ ezmyreplay.php | 30 ++++++++++++++++++------------ 8 files changed, 91 insertions(+), 48 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 composer.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..677e36e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5966153 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +.gitattributes export-ignore +.gitignore export-ignore diff --git a/README_ezab.md b/README_ezab.md index 40c6e0f..890c2d7 100644 --- a/README_ezab.md +++ b/README_ezab.md @@ -47,10 +47,10 @@ Some features of the original AB are still missing, such as POST/PUT support, et The output of the tool is also lacking. Instead of having the list of things that do work in the docs, it is suggested to run the script with the -h option. -On the other hand, there are already a couple of fetaures that we do better than the original: +On the other hand, there are already a couple of features that we do better than the original: 1. support for http 1.1 by default. AB uses http 1.0, but most of the web in 2012 runs on version 1.1. This means that the numbers you get should be closer to "real life traffic" -2. better support for keepalives (AB can only do http/1.0 keepalives, which Apache does not support when running dynamic page generators such as php) +2. better support for keep-alives (AB can only do http/1.0 keepalives, which Apache does not support when running dynamic page generators such as php) 3. easy support for compressed http responses (using the -j option) @@ -60,6 +60,6 @@ Under the hood Whatever way you choose to run the program, what happens is that the php script will execute more copies of itself, each of which will send some requests to the server. The number of processes forked depends on the "-c" parameter. -The main process waits for all chidren to terminate execution, collects their +The main process waits for all children to terminate execution, collects their metrics, aggregates them and displays the result. To debug execution of the program if anything goes wrong, run it at verbosity level 4 (option: -v 4) diff --git a/README_ezmyreplay.md b/README_ezmyreplay.md index a18a7bb..6a41c8f 100644 --- a/README_ezmyreplay.md +++ b/README_ezmyreplay.md @@ -5,7 +5,7 @@ This is a tool for benchmarking MySql database servers. It is designed to give you an impression of how your current database server installation performs, by repeatedly executing - with many parallel threads - a series of queries taken from a file. -There is no need to have a spoecific database schema or data-set installed. +There is no need to have a specific database schema or data-set installed. It is inspired by the percona-playback tool from Percona. @@ -63,7 +63,7 @@ To get a full list of supported options run the script using the -h option: Notes: . you can omit from command line arguments to specify the database to use if there - are USE statements in your sql log. Viceversa USE statements in your sql log + are USE statements in your sql log. Vice-versa USE statements in your sql log will be ignored if you specify on the command line a database to be used @@ -86,11 +86,11 @@ Under the hood Whatever way you choose to run the program, what happens is that the php script will execute more copies of itself, each of which will send some requests to the server. The number of processes forked depends on the "-c" parameter. -The main process waits for all chidren to terminate execution, collects their +The main process waits for all children to terminate execution, collects their metrics, aggregates them and displays the result. To debug execution of the program if anything goes wrong, run it at verbosity level 4 (option: -v 4) The sql log to be replayed is parsed once, and saved to a temporary file in json format. If your log takes a long time in parsing, you can make the benchmarking process faster by saving it in parsed form, using the "--dump" option, and later load -it by using "--format json" \ No newline at end of file +it by using "--format json" diff --git a/abrunner.php b/abrunner.php index 945974d..a6e2c37 100644 --- a/abrunner.php +++ b/abrunner.php @@ -9,7 +9,7 @@ * * @author G. Giunta * @license GNU GPL 2.0 - * @copyright (C) G. Giunta 2012 + * @copyright (C) G. Giunta 2012-2019 * * @todo add more cli options: verbosity * @todo AB only does http 1.0 requests; it would be nice to use siege, which can do http 1.1 - workaround: use ezab.php @@ -28,14 +28,14 @@ { die( "Sorry, web interface not yet developed..." ); // parse options in array format (die with help msg if needed) - $ab->parseOpts( $_GET ); + //$ab->parseOpts( $_GET ); } $ab->run(); } class ABRunner { - static $version = '0.1-dev'; + static $version = '0.1'; static $defaults = array( // 'real' options 'label' => '', @@ -75,13 +75,15 @@ function __construct( $opts = array() ) /** * Actual execution of the test * Depending on options, calls runTests or echoes help messages + * @throws Exception */ public function run() { switch ( $this->opts['command'] ) { case 'runtests': - return $this->runTests(); + $this->runTests(); + return; case 'versionmsg': echo $this->versionMsg(); break; @@ -89,15 +91,18 @@ public function run() echo $this->helpMsg(); break; default: - $this->abort( 1 , 'Unkown running mode: ' . $this->opts['command'] ); + $this->abort( 1 , 'Unknown running mode: ' . $this->opts['command'] ); } } + /** + * @throws Exception + */ public function runTests() { $opts = $this->opts; - $outfile = $opts['output_dir'] . '/' . $opts['summary_file']; + //$outfile = $opts['output_dir'] . '/' . $opts['summary_file']; if ( !is_dir( $opts['output_dir'] ) ) { mkdir( $opts['output_dir'] ) || $this->abort( 1, "can not create directory for output: {$opts['output_dir']}" ); @@ -295,9 +300,13 @@ protected function runABTest( $ab, $url, $concurrency, $logfilename, $aggfilenam } } + /** + * @param string $ab + * @return string + * @throws Exception + */ protected function getABExecutable( $ab='ab' ) { - $validExecutable = false; do { $output = array(); @@ -324,7 +333,8 @@ protected function getABExecutable( $ab='ab' ) /** * Parses args in argc/argv format (stores them, unless -h or -V are found, in which case only $this->opts['self'] is set) * If any unknown option is found, prints help msg and exit. - * Nb: pre-existing otions are not reset by this call. + * Nb: pre-existing options are not reset by this call. + * @throws Exception */ public function parseArgs( $argv ) { @@ -532,7 +542,7 @@ function versionMsg( $forceplaintext=false ) if ( $this->opts['outputformat'] == 'html' && !$forceplaintext ) $out .= '
';
         $out .=  "This is ABRunner, Version " . self::$version . "\n";
-        $out .= "Copyright 2012 G. Giunta, eZ Systems, http://ez.no\n";
+        $out .= "Copyright 2012-2019 G. Giunta, eZ Systems, http://ez.no\n";
         if ( $this->opts['outputformat'] == 'html' && !$forceplaintext )
             $out .= '
'; return $out; @@ -540,7 +550,7 @@ function versionMsg( $forceplaintext=false ) /** * Either exits or throws an exception - * + * @throws Exception * @todo !important when in web mode, there is little sign that there was an error... */ protected function abort( $errcode=1, $msg='' ) @@ -570,4 +580,4 @@ protected function abort( $errcode=1, $msg='' ) } } -?> \ No newline at end of file +?> diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d792ca2 --- /dev/null +++ b/composer.json @@ -0,0 +1,11 @@ +{ + "name": "gggeek/ezab", + "description": "A suite of tools for benchmarking (load testing) web servers and databases", + "keywords": ["automation", "build", "task"], + "license": "GPL-2.0", + "require": { + "php": ">=5", + "ext-curl": "*" + }, + "bin": ["abrunner.php", "ezab.php", "ezmyreplay.php"] +} diff --git a/ezab.php b/ezab.php index 218f4fe..32348c7 100644 --- a/ezab.php +++ b/ezab.php @@ -4,7 +4,7 @@ * * @author G. Giunta * @license GNU GPL 2.0 - * @copyright (C) G. Giunta 2010-2012 + * @copyright (C) G. Giunta 2010-2019 * * It uses curl for executing the http requests. * It uses a multi-process scheme (tested to be working both on windows and linux): @@ -27,7 +27,7 @@ if ( !defined( 'EZAB_AS_LIB' ) ) { - if( !function_exists( 'curl_init' ) ) + if ( !function_exists( 'curl_init' ) ) { echo( 'Missing cURL, cannot run' ); exit( 1 ); @@ -50,7 +50,7 @@ class eZAB { - static $version = '0.3-dev'; + static $version = '0.3'; static $defaults = array( // 'real' options /// How much troubleshooting info to print. According to ab docs: @@ -58,8 +58,8 @@ class eZAB /// Real life testing seem to tell a different story though... 'verbosity' => 1, // -v verbosity 'children' => 1, // -c concurrency Number of multiple requests to make - 'tries' => 1, // -n requests Number of requests to perform - 'timeout' => 0, // -t timelimit Seconds to max. wait for responses + 'tries' => 1, // -n requests Number of requests to perform + 'timeout' => 0, // -t timelimit Seconds to max. wait for responses 'auth' => false, 'proxy' => false, 'proxyauth' => false, @@ -97,6 +97,7 @@ function __construct( $opts = array() ) /** * Actual execution of the test, echoes results to stdout. * Depending on options, calls runParent or runChild, or echoes help messages + * @throws Exception */ public function run() { @@ -114,7 +115,7 @@ public function run() echo $this->helpMsg(); break; default: - $this->abort( 1 , 'Unkown running mode: ' . $this->opts['command'] ); + $this->abort( 1 , 'Unknown running mode: ' . $this->opts['command'] ); } } @@ -122,6 +123,7 @@ public function run() * Runs the test, prints results (unless verbosity option has been set to 0). * Note: sets a value to $this->opts['parentid'], too * @return array + * @throws Exception */ public function runParent() { @@ -207,7 +209,7 @@ public function runParent() //$starttimes = array(); $pipes = array(); $childprocs = array(); - $childresults = array(); + //$childresults = array(); //$time = microtime( true ); @@ -241,7 +243,7 @@ public function runParent() // wait for all children to finish /// @todo add a global timeout limit? $finished = 0; - $outputs = array(); + //$outputs = array(); do { /// @todo !important lower this - use usleep @@ -423,7 +425,7 @@ public function runChild() if ( $curl ) { curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); - // enbale receiving header too. We will need later to split by ourselves headers from body to calculate correct sizes + // enable receiving header too. We will need later to split by ourselves headers from body to calculate correct sizes curl_setopt( $curl, CURLOPT_HEADER, true ); curl_setopt( $curl, CURLOPT_USERAGENT, "eZAB " . self::$version ); if ( $opts['timeout'] > 0 ) @@ -578,7 +580,7 @@ public function runChild() } /** - * Parse the ouput of children processes and calculate global stats + * Parse the output of children processes and calculate global stats */ protected function parseOutputs( $outputs ) { @@ -692,9 +694,13 @@ protected function parseOutputs( $outputs ) return $resp; } + /** + * @param string $php + * @return string + * @throws Exception + */ protected function getPHPExecutable( $php='php' ) { - $validExecutable = false; do { $output = array(); @@ -721,7 +727,8 @@ protected function getPHPExecutable( $php='php' ) /** * Parses args in argc/argv format (stores them, unless -h or -V are found, in which case only $this->opts['self'] is set) * If any unknown option is found, prints help msg and exit. - * Nb: pre-existing otions are not reset by this call. + * Nb: pre-existing options are not reset by this call. + * @throws Exception */ public function parseArgs( $argv ) { @@ -812,10 +819,10 @@ public function parseArgs( $argv ) $opts['childnr'] = (int)$val; $opts['command'] = 'runchild'; break; - case 'i': + case 'i': $opts['head'] = true; break; - case 'j': + case 'j': $opts['respencoding'] = true; break; case 'k': @@ -1037,7 +1044,7 @@ function versionMsg() if ( $this->opts['outputformat'] == 'html' ) $out .= '
';
         $out .=  "This is eZAB, Version " . self::$version . "\n";
-        $out .= "Copyright 2010-2012 G. Giunta, eZ Systems, http://ez.no\n";
+        $out .= "Copyright 2010-2019 G. Giunta, eZ Systems, http://ez.no\n";
         if ( $this->opts['outputformat'] == 'html' )
             $out .= '
'; return $out; @@ -1045,7 +1052,7 @@ function versionMsg() /** * Either exits or throws an exception - * + * @throws Exception * @todo !important when in web mode, there is little sign that there was an error... */ protected function abort( $errcode=1, $msg='' ) @@ -1074,5 +1081,3 @@ protected function abort( $errcode=1, $msg='' ) } } } - -?> \ No newline at end of file diff --git a/ezmyreplay.php b/ezmyreplay.php index 48ae4d3..2968747 100644 --- a/ezmyreplay.php +++ b/ezmyreplay.php @@ -5,7 +5,7 @@ * * @author G. Giunta * @license GNU GPL 2.0 - * @copyright (C) G. Giunta 2012 + * @copyright (C) G. Giunta 2012-2019 * * It uses a multi-process scheme (tested to be working both on windows and linux): * you will need php-cli installed for this to work. @@ -46,7 +46,7 @@ class eZMyReplay { - static $version = '0.1-dev'; + static $version = '0.1'; static $defaults = array( // 'real' options 'verbosity' => 1, // -v verbosity How much troubleshooting info to print @@ -97,6 +97,7 @@ function __construct( $opts = array() ) /** * Actual execution of the test, echoes results to stdout. * Depending on options, calls runParent or runChild, or echoes help messages + * @throws Exception */ public function run() { @@ -125,6 +126,7 @@ public function run() * Runs the test, prints results (unless verbosity option has been set to 0). * Note: sets a value to $this->opts['parentid'], too * @return array + * @throws Exception */ public function runParent( $only_return_parsed=false ) { @@ -212,7 +214,7 @@ public function runParent( $only_return_parsed=false ) //$starttimes = array(); $pipes = array(); $childprocs = array(); - $childresults = array(); + //$childresults = array(); //$time = microtime( true ); @@ -247,7 +249,7 @@ public function runParent( $only_return_parsed=false ) // wait for all children to finish /// @todo add a global timeout limit? $finished = 0; - $outputs = array(); + //$outputs = array(); do { /// @todo !important lower this - use usleep @@ -348,7 +350,7 @@ public function runParent( $only_return_parsed=false ) "\nReport\n" . "------\n" . "Executed {$data['tries']} queries\n" . - "Spent " . gmstrftime( '%H:%M:%S', (int)$data['tot_time'] ) . substr( strstr( $data['tot_time'], '.' ), 0, 7 ) . " executing queries\n" //. ( $hasmeta ? " versus an expected XX time.\n" : "\n" ) . + "Spent " . gmstrftime( '%H:%M:%S', (int)$data['tot_time'] ) . substr( strstr( $data['tot_time'], '.' ), 0, 7 ) . " executing queries\n" . //. ( $hasmeta ? " versus an expected XX time.\n" : "\n" ) . ( $hasmeta ? "{$data['meta']['faster']} queries were quicker than expected, {$data['meta']['slower']} were slower\n" : "" ) . "A total of {$data['failures']} queries had errors.\n" . ( $hasmeta ? "Expected {$data['rows_expected']} rows, got {$data['tot_rows']} (a difference of " . ( $data['rows_expected'] - $data['tot_rows'] ) . ")\n" : "" ) . @@ -372,7 +374,7 @@ public function runParent( $only_return_parsed=false ) /** * Executes the sql queries, returns a csv string with the collected data * @return string - * + * @throws Exception * @todo add support for pdo, mysql */ public function runChild() @@ -455,7 +457,7 @@ public function runChild() $fetched = 0; $start = microtime( true ); $res = $my->query( $stmt['sql'] ); - $ar = $my->affected_rows; + //$ar = $my->affected_rows; if ( is_object( $res ) ) { // we get all data line by line, not to exhaust php memory by fetching all in 1 array @@ -817,9 +819,14 @@ protected function parseOutputs( $outputs ) return $resp; } + /** + * @param string $php + * @return string + * @throws Exception + */ protected function getPHPExecutable( $php='php' ) { - $validExecutable = false; + //$validExecutable = false; do { $output = array(); @@ -847,6 +854,7 @@ protected function getPHPExecutable( $php='php' ) * Parses args in argc/argv format (stores them, unless -h or -V are found, in which case only $this->opts['self'] is set) * If any unknown option is found, prints help msg and exit. * Nb: pre-existing otions are not reset by this call. + * @throws Exception */ public function parseArgs( $argv ) { @@ -1139,7 +1147,7 @@ function versionMsg() protected function copyrightMsg() { - $out = "Copyright (C) 2012 by G. Giunta, eZ Systems, http://ez.no\n"; + $out = "Copyright (C) 2012-2019 by G. Giunta, eZ Systems, http://ez.no\n"; $out .= "This is free software; see the source for copying conditions.\n"; $out .= "There is NO warranty; not even for MERCHANTABILITY or FITNESS\n"; $out .= "FOR A PARTICULAR PURPOSE."; @@ -1148,7 +1156,7 @@ protected function copyrightMsg() /** * Either exits or throws an exception - * + * @throws Exception * @todo !important when in web mode, there is little sign that there was an error... */ protected function abort( $errcode=1, $msg='' ) @@ -1177,5 +1185,3 @@ protected function abort( $errcode=1, $msg='' ) } } } - -?> \ No newline at end of file