Blazingly-Fast, Event-Driven, Asynchronous PHP. Berlin PHP Usergroup 02/06/2018
Christoph Lühr@chluehr / bephpug 2018"Fast, faster, Swoole"Teaser:Swoole in 5 Minutes
View Slide
SINCE2000
"Blazingly-Fast,Event-Driven,Asynchronous PHP."
$ pecl install swoole
$ brew install swoole
$server = new \Swoole\Http\Server('0.0.0.0', 9000);$server->on('Request', function ($request, $response) {$response->end('OK');});$server->start();
$loop = React\EventLoop\Factory::create();$server = stream_socket_server('tcp://0.0.0.0:9000');stream_set_blocking($server, 0);$loop->addReadStream($server, function ($server) use ($loop) {$conn = stream_socket_accept($server);$data = "HTTP/1.1 200 OK\r\nContent-Length: 3\r\n\r\nHi\n";$loop->addWriteStream($conn, function ($conn) use (&$data, $loop) {$written = fwrite($conn, $data);if ($written === strlen($data)) {fclose($conn);$loop->removeStream($conn);} else {$data = substr($data, $written);}});});$loop->run();
PHP-PM
Sugar and Cream?(PHP is not enough ...)
Async IO
File I/O(and some tagline to go along)
TCP ClientsMySQL / Redis / HTTP / WebSocket
"Reality Distortion"BENCHMARKS
300.000Req/Sec
wrk -t4 -c400 -d10s http://127.0.0.1:1337/Running 10s test @ http://127.0.0.1:1337/4 threads and 400 connectionsThread Stats Avg Stdev Max +/- StdevLatency 1.46ms 1.42ms 27.96ms 85.66%Req/Sec 75.29k 36.43k 183.55k 72.75%3007806 requests in 10.06s, 605.25MB readRequests/sec: 299103.32Transfer/sec: 60.19MB
wrk -t16 -c400 -d30s http://localhost:9000/Running 30s test @ http://localhost:9000/16 threads and 400 connectionsThread Stats Avg Stdev Max +/- StdevLatency 6.97ms 7.07ms 226.95ms 93.28%Req/Sec 4.00k 0.96k 15.36k 76.15%1909179 requests in 30.09s, 282.21MB readRequests/sec: 63442.77Transfer/sec: 9.38MB
Demo
Real World(tm)References?
To good to be true...?DRAWBACKS
中文
Thanks!Questions?Christoph Lühr[email protected] [email protected] @chluehrSlides license Attribution-NonCommercial-ShareAlike 3.0 http://creativecommons.org/licenses/by-nc-sa/3.0/
● Swoole 2.0https://www.swoole.co.uk/