amphp / byte-stream

A non-blocking stream abstraction for PHP based on Amp.
https://amphp.org/byte-stream
MIT License
364 stars 31 forks source link

Immediate reads and writes might result in blocking #49

Closed kelunik closed 5 years ago

kelunik commented 5 years ago

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.

trowski commented 5 years ago

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.

kelunik commented 5 years ago

I think it's fine for now then.