PHP Classes

File: src/bin/bench

Recommend this page to a friend!
  Classes of Insolita   PHP Async HTTP Client Benchmarks   src/bin/bench   Download  
File: src/bin/bench
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Async HTTP Client Benchmarks
Measure the performance of different HTTP clients
Author: By
Last change:
Date: 3 years ago
Size: 1,983 bytes
 

Contents

Class file image Download
#! /usr/bin/env php
<?php
use app\Bench;
use
app\BenchDb;

require
__DIR__ . '/../vendor/autoload.php';

$options = getopt('t:b::c::i::', ['batch::', 'iters::', 'conk::', 'db::', 'help::']);
if(isset(
$options['help'])){
   
usage();
    exit(
0);
}

$client = $options['t'] ?? null;
if(!
$client || ! in_array($client, ['guzzle','react', 'amp'])){
    echo
'Please, define one of clients for benchmark (guzzle, react, amp)'.PHP_EOL;
   
usage();
    exit();
}

$batchSize = (int)($options['b'] ?? $options['batch'] ?? 0);
if(
$batchSize > 6000){
   
$batchSize = 6000;
}
if(
$batchSize <= 0){
   
$batchSize = 10;
}


$concurrency = (int)($options['c'] ?? $options['conk'] ?? 0);
if(
$concurrency <= 0){
   
$concurrency = 25;
}

$iterations = (int)($options['i']?? $options['iters'] ?? 0);
if(
$iterations <= 0){
   
$iterations = 1;
}

$useDb = isset($options['db']);

$mem = memory_get_peak_usage();
if(!
$useDb){
   (new
Bench($client, $iterations, $concurrency, $batchSize))->run();
}else{
   
$dbconf = ['dsn'=>'pgsql:host=db;dbname=pgtest', 'host'=>'db','dbname'=>'pgtest', 'user'=>'pgdev', 'pass'=>'pgdev'];
    (new
BenchDb($client, $iterations, $batchSize, $dbconf))->run();
}

$memEnd = memory_get_peak_usage();
$memDelta = round(($memEnd - $mem)/(1024*1024), 2);
var_dump(compact('mem', 'memEnd', 'memDelta'));

function
usage(){
    echo <<<TXT
Simple usage:
           bench -t={clientname}
    Full featured usage examples:
           becnh -t=react -b5000 -c25 -i5
           bench -t=guzzle --batch=200 --conk=5 --iters=5 --db
    Options:
           -t Required, one of clients - react, guzzle, amp
           -b --batch (how many urls should be fetched, max = 6000)
           -c --conk Request concurrency
           -i --iters Number of iterations for run benchmark and than calculate average time
           --db Benchmark with database version, instead of file version
           --help Show this instruction
          

TXT;

}