amphp / byte-stream

A non-blocking stream abstraction for PHP based on Amp.

Home Page:https://amphp.org/byte-stream

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Immediate reads and writes might result in blocking

kelunik opened this issue · comments

A tight loop of reading and writing with data always being available and always writable, might result in a blocking loop. We should discuss measures to mitigate that, e.g. scheduling immediate write with a Loop::defer() in case many of them happen in a tight loop.

Looks like this came up in the past for reading, as we already have this defer when reading. For writing we can skip attempting the write and always enable the write watcher, which will push queued writes to the next tick.

Edit: On second thought, that would add a lot of latency to writing… either it's fine as-is with the read defer or we need some other trigger to delay writing for a tick.

I think it's fine for now then.