Skip to content

Commit

Permalink
Add composer.json; fix typos in comments; remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Dec 3, 2019
1 parent 706eeed commit 07d3f44
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 48 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gitattributes export-ignore
.gitignore export-ignore
6 changes: 3 additions & 3 deletions README_ezab.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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)
8 changes: 4 additions & 4 deletions README_ezmyreplay.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down Expand Up @@ -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


Expand All @@ -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"
it by using "--format json"
32 changes: 21 additions & 11 deletions abrunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' => '',
Expand Down Expand Up @@ -75,29 +75,34 @@ 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;
case 'helpmsg':
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']}" );
Expand Down Expand Up @@ -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();
Expand All @@ -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 )
{
Expand Down Expand Up @@ -532,15 +542,15 @@ function versionMsg( $forceplaintext=false )
if ( $this->opts['outputformat'] == 'html' && !$forceplaintext )
$out .= '<pre>';
$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 .= '</pre>';
return $out;
}

/**
* 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='' )
Expand Down Expand Up @@ -570,4 +580,4 @@ protected function abort( $errcode=1, $msg='' )
}
}

?>
?>
11 changes: 11 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"]
}
41 changes: 23 additions & 18 deletions ezab.php
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 );
Expand All @@ -50,16 +50,16 @@

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:
/// "4 and above prints information on headers, 3 and above prints response codes (404, 200, etc.), 2 and above prints warnings and info."
/// 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,
Expand Down Expand Up @@ -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()
{
Expand All @@ -114,14 +115,15 @@ 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'] );
}
}

/**
* 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()
{
Expand Down Expand Up @@ -207,7 +209,7 @@ public function runParent()
//$starttimes = array();
$pipes = array();
$childprocs = array();
$childresults = array();
//$childresults = array();

//$time = microtime( true );

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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();
Expand All @@ -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 )
{
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -1037,15 +1044,15 @@ function versionMsg()
if ( $this->opts['outputformat'] == 'html' )
$out .= '<pre>';
$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 .= '</pre>';
return $out;
}

/**
* 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='' )
Expand Down Expand Up @@ -1074,5 +1081,3 @@ protected function abort( $errcode=1, $msg='' )
}
}
}

?>
Loading

0 comments on commit 07d3f44

Please sign in to comment.