Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP7.1 is fast(?)

uzulla
January 01, 2017

PHP7.1 is fast(?)

2017/?/? (forgot)
at somewhere.

this is kind of (joke|comedy).

uzulla

January 01, 2017
Tweet

More Decks by uzulla

Other Decks in Programming

Transcript

  1. by the way... php can't to be standalone httpd. right?

    (php -s is for only development use) (btw, hhvm can be !) If will benchmark with apache/nginx, that is unfair(???)
  2. Write git clone code. 4 httpd, written by php 4

    https://github.com/uzulla/ ReactPHP_PostSupportSample 4 include monolog, twig(template engine.)
  3. <?php require_once 'vendor/autoload.php'; $loader = new Twig_Loader_Filesystem(__DIR__.'/templates'); $twig = new

    Twig_Environment($loader, [ 'cache' => __DIR__.'/twig_cache', ]); $access_log = new \Monolog\Logger('access'); $access_log->pushHandler(new \Monolog\Handler\StreamHandler(__DIR__.'/access.log', \Monolog\Logger::INFO)); // app $app = function (\Uzulla\React\Http\Request $req,\React\Http\Response $res) use ($twig, $access_log) { $path = $req->getPath(); $method = $req->getMethod(); $access_log->addInfo("{$method}\t{$path}"); $params = [ 'params'=>$req->getParams(), 'query'=>$req->getQuery() ]; if($method === 'GET' && preg_match('|\A/\z|u', $path)){ $res->writeHead(200, ['Content-Type' => 'text/html']); $res->end($twig->render('index.twig',$params)); }elseif($method === 'POST' && preg_match('|\A/\z|u', $path)){ $res->writeHead(200, ['Content-Type' => 'text/html']); $res->end($twig->render('index.twig',$params)); }else{ $res->writeHead(404, ['Content-Type' => 'text/html']); $res->end($twig->render('notfound.twig')); } }; // build reactor $loop = React\EventLoop\Factory::create(); $socket = new React\Socket\Server($loop); $http = new \Uzulla\React\Http\Server($socket); $http->on('request', $app); $socket->listen(8080); echo "running...\n"; $loop->run();
  4. !

  5. okey, wrk is dosen't work. try with httperf ! 4

    https://github.com/httperf/httperf
  6. me: I'm screwed lestrrat ( a.k.a daisuke maki): Why don't

    you write a bechmarker yourself ? me: what?
  7. <?php $c = 10000 ; $target = "http://127.0.0.1:8080" ; $start_usec

    = microtime(true); for( $i=0; $c>$i; $i++ ){ $res = file_get_contents($target); } $used_time = (microtime(true) - $start_usec) ; echo ceil( 1/( $used_time/$c ) ); echo "req/sec";
  8. I thought, this is slow benchmark tool. ! I want

    more faster". but how? I need concurrent.! but, this is php. (curl_multi ? yes...but... ) OK! WE NEED FORK! !
  9. <?php $max_worker = 10; $c = 10000; $c_ = $c/$max_worker;

    $target="http://127.0.0.1:8080"; $start_usec = microtime(true); $pids=[]; for($x=0;$max_worker>$x;$x++){ $pid = pcntl_fork(); if ($pid == -1) { die("fork failed");} else if ($pid) { $pids[]=$pid; } else { for($i=0;$c_>$i;$i++){ $res = file_get_contents($target); } exit; } } foreach($pids as $pid){ pcntl_waitpid($pid, $status); } $used_time = (microtime(true) - $start_usec) ; echo ceil( 1/( $used_time/$c ) ), "req/sec";
  10. my httpd is BAD, that is why!!! ! I use

    nginx to benchmark my benchmark!! !
  11. meanwhile in apache bench... 4 ab -c 10 -n 10000

    http://nginx/ 4 Requests per second: 15273.21
  12. conclusion my bench (written by PHP) 0.9 times faster than

    AB !! ( DISCLAIMER, THIS RESULT IS REAL RESULT. BUT JUST PLAYING.)
  13. Other benchmarks. 4 php7.1.2 with my_httpd + fork_bench.php(c:10) 4 3858req/sec

    4 php5.6.30 with my_httpd + fork_bench.php(c:10) 4 2425req/sec 4 hhvm3.18.1 with my_httpd + fork_bench.php(c:10) 4 2377req/sec 4 (but, hhvm w/o libevent)