uszanowanko programowanko #4 - reactphp - reaktor jadrowy w php

15
ReactPHP - reaktor jądrowy w PHP Krzysztof Korzeniewski [email protected]

Upload: the-software-house

Post on 08-Aug-2015

788 views

Category:

Technology


3 download

TRANSCRIPT

ReactPHP - reaktor jądrowy w PHP

Krzysztof Korzeniewski [email protected]

Reactor pattern

ReactPHP is based on the reactor pattern, hence the name. A reactor system is always single threaded by definition and

uses an event loop to handle different kind of events.

Event handling pattern for handling service requests delivered concurrently to a service handler by one or more inputs

- Resources

- Synchronous Event Demultiplexer

- Dispatcher

- Request / Event Handler

popen() proc_open() pcntl_fork()

stream_select() / stream_set_blocking() curl_multi_select()

system(’sleep 1000 &’) system(’screen -dm sleep 1000’)

Event-driven Non-blocking I/O

Pure PHP Native extensions

LibEventLoop - pecl libevent LibEvLoop - pecl libev

ExtEventLoop - pecl event StreamSelectLoop - stream_select()

EventLoop Component

Ticks Timers

Streams Promises

Filesystem - pecl eio -> libeio Sockets

Socket client Child processes

Components

app.php

app.js

Benchmark time !

ab -c 1000 -n 10000 http://127.0.0.1:1337/

php app.php

node app.js

hhvm app.php

0 2500 5000 7500 10000

1056

1288

2265

9471

7765

4426

requests / sec time taken (ms)

i7 2,4 GHz

Pros Cons

- difficult to debug - limited scalability - current version 0.4.1

- separates app code - lowers bootstraping costs

More ?

Pattern-oriented software architecture. 2, Patterns for concurrent and networked objects / Douglas Schmidt

https://www.youtube.com/watch?v=lnQeiY_BoeQ

http://blog.wyrihaximus.net/tags/reactphp/Cees-Jan Kiewiet

#AMA