Jeremy Mikola
jmikola
stream_socket_accept($server, -1)
Why is this a problem?
L1 cache reference | 0.5 ns |
Branch mispredict | 5 ns |
L2 cache reference | 7 ns |
Mutex lock/unlock | 25 ns |
Main memory reference | 100 ns |
Send 1K bytes over 1 Gbps network | 10,000 ns |
Read 4K randomly from SSD | 150,000 ns |
Read 1 MB sequentially from memory | 250,000 ns |
Round trip within same datacenter | 500,000 ns |
Read 1 MB sequentially from SSD | 1,000,000 ns |
Disk seek | 10,000,000 ns |
Read 1 MB sequentially from disk | 20,000,000 ns |
Round trip from US to Europe | 150,000,000 ns |
L1 cache reference | 0.5 ns |
Branch mispredict | 5 ns |
L2 cache reference | 7 ns |
Mutex lock/unlock | 25 ns |
Main memory reference | 100 ns |
Send 1K bytes over 1 Gbps network | 10,000 ns |
Read 4K randomly from SSD | 150,000 ns |
Read 1 MB sequentially from memory | 250,000 ns |
Round trip within same datacenter | 500,000 ns |
Read 1 MB sequentially from SSD | 1,000,000 ns |
Disk seek | 10,000,000 ns |
Read 1 MB sequentially from disk | 20,000,000 ns |
Round trip from US to Europe | 150,000,000 ns |
You can buy a 1000MHz machine with 2 gigabytes of RAM and an 1000Mbit/sec Ethernet card for $1200 or so. At 20000 clients, that’s 50KHz, 100Kbytes, and 50Kbits/sec per client.
It shouldn’t take any more horsepower than that to take four kilobytes from the disk and send them to the network once a second for each of twenty thousand clients.
So hardware is no longer the bottleneck.
Readable → Writable
Joins writable and readable streams
Allows data to be filtered
Converts writable stream to a promise
Wouldn’t it be nice if asynchronous
functions could return immediately?
promise()
resolve($value = null)
reject($reason = null)
progress($update = null)
Computation or unit of work that
may not have completed yet
Placeholder for the result of a deferred computation
then($onFulfilled, $onRejected, $onProgress)
then()
returns a new Promise composing the first
“You’re missing the point of promises”
— Domenic Denicola
Now back to the stack…
Inter-process communication
Message queues
Break up computations with$loop->nextTick(callable)
$ composer require "react/react=~0.4"
https://github.com/videlalvaro/gifsockets
https://github.com/reactphp/gifsocket