Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
PHP7.1 is fast(?)
Search
uzulla
January 01, 2017
Programming
1
1.5k
PHP7.1 is fast(?)
2017/?/? (forgot)
at somewhere.
this is kind of (joke|comedy).
uzulla
January 01, 2017
Tweet
Share
More Decks by uzulla
See All by uzulla
似たもの同士のPerlとPHP
uzulla
1
170
More Context, Better Code. 既存コードやOAS等をコンテキストとしてLLMに与える事で、よりよいコード生成を行う話
uzulla
1
130
あなたのアプリ、ログはでてますか?あるいはログをだしてますか? (Funabashi.dev用 軽量版)
uzulla
3
210
セッションのトークセッション / Traps for PHP session features in growing web apps
uzulla
2
150
Crafting a Own PHP - ウキウキ手作りミニマリストPHP
uzulla
5
2.2k
例外を投げるのをやめてみないか? あるいは受け入れてみないか? - How to use exceptions other than throwing
uzulla
4
1k
PHPerが ISUCONでやるべき事
uzulla
1
1.1k
開発生産性は上がらない - N Ways to Reduce Development Productivity
uzulla
1
270
test is not a job
uzulla
1
520
Other Decks in Programming
See All in Programming
楽しく向き合う例外対応
okutsu
0
620
AIプログラミング雑キャッチアップ
yuheinakasaka
17
4.3k
もう少しテストを書きたいんじゃ〜 #phpstudy
o0h
PRO
17
3.9k
.NET Frameworkでも汎用ホストが使いたい!
tomokusaba
0
200
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
1k
DRFを少しずつ オニオンアーキテクチャに寄せていく DjangoCongress JP 2025
nealle
2
270
密集、ドキュメントのコロケーション with AWS Lambda
satoshi256kbyte
1
210
CI改善もDatadogとともに
taumu
0
200
Jakarta EE meets AI
ivargrimstad
0
380
Django NinjaによるAPI開発の効率化とリプレースの実践
kashewnuts
1
250
もう僕は OpenAPI を書きたくない
sgash708
5
1.9k
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
150
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
The Invisible Side of Design
smashingmag
299
50k
Statistics for Hackers
jakevdp
797
220k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Unsuck your backbone
ammeep
669
57k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Side Projects
sachag
452
42k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.4k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
RailsConf 2023
tenderlove
29
1k
Transcript
PHP7.1 is fast(?)
name: ͍ͩ͠͡ΎΜ͍ͪ (Ishida) nick: uzulla (͏ͣΒ) fun: PHP and !
conclusion 7.1 is fast ! (but any evidence here)
need benchmark !!
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(???)
use "ReactPHP"! (use libevent) standalone httpd(and other), that written by
PHP!
Test Enviroment 4 VPS (Vultr, $5/mo) 4 1Core 4 1GB
mem 4 ubuntu 16.10 4 PHP7.1.2
Write git clone code. 4 httpd, written by php 4
https://github.com/uzulla/ ReactPHP_PostSupportSample 4 include monolog, twig(template engine.)
<?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();
$ git clone THAT $ composer install $ php boot.php
listen...
ab(apache bench) 4 ab -n 10000 -c 10 http://127.0.0.1:8080/
Requests per second: 3477.39 #/sec
okay, try more concurrent connection.
5000 concurrent 4 ab -n 10000 -c 5000 http://127.0.0.1:8080/
fail 4 socket: Too many open files (24)
ok, ab's limits. try another tool. apt install wrk 4
https://github.com/wg/wrk
wrk 4 wrk -c 5000 -d 5 http://127.0.0.1:8080/
Requests/sec 98.16
tooooo slow, hmmm, concurrent overkill? try 1000 concurrent (same as
ab's test).
4 wrk -c 1000 -d 5 http://127.0.0.1:8080/ 4 Requests/sec: 83.17
!
okey, wrk is dosen't work. try with httperf ! 4
https://github.com/httperf/httperf
httperf 4 httperf --port=8080 --server=127.0.0.1 -- rate=2800 --num-conns=10000 --hog
Request rate: 2799.6 req/s
seems good. but, is this correct? I need try more
tools !
siege 4 siege -c 100 http://127.0.0.1:8080/ 4 Transaction rate: 393.35
trans/sec
Untrustworthy... (Of course, these bench mark tools are more trustworthy
than weird httpd.)
all results (?) ab: 3477.3 #/sec wrk: 98.1 req/sec httperf:
2799.6 req/s siege: 393.3 trans/sec
me: I'm screwed lestrrat ( a.k.a daisuke maki): Why don't
you write a bechmarker yourself ? me: what?
me: OK, I'll write tools! (at YESTERDAY 11:36 pm)
I wrote "benchmark.php" !! (ta daaa!)
<?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";
haha... yes, just kidding. let's play.
(unreliable) result 4 3,731 req/sec
I can't believe this result. (faster than ab ;lol) it's
not bad. but ...
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! !
<?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";
2881req/sec (no fork ver 3,731 req/sec)
no no, more slow !!! !
! need more core!!!
create 4core 8GB mem server !
benchmark.php 4147req/sec fork_benchmark.php 3995req/sec
NO! why fork ver is more slow!? !
my httpd is BAD, that is why!!! ! I use
nginx to benchmark my benchmark!! !
result(?) with nginx 4 benchmark.php 4 6817req/sec 4 fork_benchmark.php 4
13730req/sec
OK! 4 fork ver faster than not fork ver!!
( what is ok? )
meanwhile in apache bench... 4 ab -c 10 -n 10000
http://nginx/ 4 Requests per second: 15273.21
compare own tool and ab. 4 fork_benchmark.php: 4 13,730 req/sec
4 ab: 4 15,273.21 #/sec
okey!(?)
conclusion my bench (written by PHP) 0.9 times faster than
AB !! ( DISCLAIMER, THIS RESULT IS REAL RESULT. BUT JUST PLAYING.)
OK !!
"what is ok?" (now 2:12 am)
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)
conclusion PHP7.1 is fast (1.6x faster than 5.6 (at this
test))
(REAL) conclusion USE RELIABLE TOOLS USE NGINX DON'T USE PHP
FOR WRITE A BENCHMARK TOOL
but fun. PHP is waiting New Challengers ..... FIN
//NEXT use pthread;