Slide 1

Slide 1 text

PHP7.1 is fast(?)

Slide 2

Slide 2 text

name: ͍ͩ͠͡ΎΜ͍ͪ (Ishida) nick: uzulla (͏ͣΒ) fun: PHP and !

Slide 3

Slide 3 text

conclusion 7.1 is fast ! (but any evidence here)

Slide 4

Slide 4 text

need benchmark !!

Slide 5

Slide 5 text

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(???)

Slide 6

Slide 6 text

use "ReactPHP"! (use libevent) standalone httpd(and other), that written by PHP!

Slide 7

Slide 7 text

Test Enviroment 4 VPS (Vultr, $5/mo) 4 1Core 4 1GB mem 4 ubuntu 16.10 4 PHP7.1.2

Slide 8

Slide 8 text

Write git clone code. 4 httpd, written by php 4 https://github.com/uzulla/ ReactPHP_PostSupportSample 4 include monolog, twig(template engine.)

Slide 9

Slide 9 text

__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();

Slide 10

Slide 10 text

$ git clone THAT $ composer install $ php boot.php listen...

Slide 11

Slide 11 text

ab(apache bench) 4 ab -n 10000 -c 10 http://127.0.0.1:8080/

Slide 12

Slide 12 text

Requests per second: 3477.39 #/sec

Slide 13

Slide 13 text

okay, try more concurrent connection.

Slide 14

Slide 14 text

5000 concurrent 4 ab -n 10000 -c 5000 http://127.0.0.1:8080/

Slide 15

Slide 15 text

fail 4 socket: Too many open files (24)

Slide 16

Slide 16 text

ok, ab's limits. try another tool. apt install wrk 4 https://github.com/wg/wrk

Slide 17

Slide 17 text

wrk 4 wrk -c 5000 -d 5 http://127.0.0.1:8080/

Slide 18

Slide 18 text

Requests/sec 98.16

Slide 19

Slide 19 text

tooooo slow, hmmm, concurrent overkill? try 1000 concurrent (same as ab's test).

Slide 20

Slide 20 text

4 wrk -c 1000 -d 5 http://127.0.0.1:8080/ 4 Requests/sec: 83.17

Slide 21

Slide 21 text

!

Slide 22

Slide 22 text

okey, wrk is dosen't work. try with httperf ! 4 https://github.com/httperf/httperf

Slide 23

Slide 23 text

httperf 4 httperf --port=8080 --server=127.0.0.1 -- rate=2800 --num-conns=10000 --hog

Slide 24

Slide 24 text

Request rate: 2799.6 req/s

Slide 25

Slide 25 text

seems good. but, is this correct? I need try more tools !

Slide 26

Slide 26 text

siege 4 siege -c 100 http://127.0.0.1:8080/ 4 Transaction rate: 393.35 trans/sec

Slide 27

Slide 27 text

Untrustworthy... (Of course, these bench mark tools are more trustworthy than weird httpd.)

Slide 28

Slide 28 text

all results (?) ab: 3477.3 #/sec wrk: 98.1 req/sec httperf: 2799.6 req/s siege: 393.3 trans/sec

Slide 29

Slide 29 text

me: I'm screwed lestrrat ( a.k.a daisuke maki): Why don't you write a bechmarker yourself ? me: what?

Slide 30

Slide 30 text

me: OK, I'll write tools! (at YESTERDAY 11:36 pm)

Slide 31

Slide 31 text

I wrote "benchmark.php" !! (ta daaa!)

Slide 32

Slide 32 text

$i; $i++ ){ $res = file_get_contents($target); } $used_time = (microtime(true) - $start_usec) ; echo ceil( 1/( $used_time/$c ) ); echo "req/sec";

Slide 33

Slide 33 text

haha... yes, just kidding. let's play.

Slide 34

Slide 34 text

(unreliable) result 4 3,731 req/sec

Slide 35

Slide 35 text

I can't believe this result. (faster than ab ;lol) it's not bad. but ...

Slide 36

Slide 36 text

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! !

Slide 37

Slide 37 text

$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";

Slide 38

Slide 38 text

2881req/sec (no fork ver 3,731 req/sec)

Slide 39

Slide 39 text

no no, more slow !!! !

Slide 40

Slide 40 text

! need more core!!!

Slide 41

Slide 41 text

create 4core 8GB mem server !

Slide 42

Slide 42 text

benchmark.php 4147req/sec fork_benchmark.php 3995req/sec

Slide 43

Slide 43 text

NO! why fork ver is more slow!? !

Slide 44

Slide 44 text

my httpd is BAD, that is why!!! ! I use nginx to benchmark my benchmark!! !

Slide 45

Slide 45 text

result(?) with nginx 4 benchmark.php 4 6817req/sec 4 fork_benchmark.php 4 13730req/sec

Slide 46

Slide 46 text

OK! 4 fork ver faster than not fork ver!!

Slide 47

Slide 47 text

( what is ok? )

Slide 48

Slide 48 text

meanwhile in apache bench... 4 ab -c 10 -n 10000 http://nginx/ 4 Requests per second: 15273.21

Slide 49

Slide 49 text

compare own tool and ab. 4 fork_benchmark.php: 4 13,730 req/sec 4 ab: 4 15,273.21 #/sec

Slide 50

Slide 50 text

okey!(?)

Slide 51

Slide 51 text

conclusion my bench (written by PHP) 0.9 times faster than AB !! ( DISCLAIMER, THIS RESULT IS REAL RESULT. BUT JUST PLAYING.)

Slide 52

Slide 52 text

OK !!

Slide 53

Slide 53 text

"what is ok?" (now 2:12 am)

Slide 54

Slide 54 text

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)

Slide 55

Slide 55 text

conclusion PHP7.1 is fast (1.6x faster than 5.6 (at this test))

Slide 56

Slide 56 text

(REAL) conclusion USE RELIABLE TOOLS USE NGINX DON'T USE PHP FOR WRITE A BENCHMARK TOOL

Slide 57

Slide 57 text

but fun. PHP is waiting New Challengers ..... FIN

Slide 58

Slide 58 text

//NEXT use pthread;