Replace Events polling with notifications#389
Conversation
|
This isn't really an acceptable approach, it has consequences for those not using the events api - we can't really lock a global mutex for link operations, it will introduce too much contention and even users not using the events api pay the significant price. I have an idea for an alternative approach I've been mulling over for a while that might allow us to simply remove the events API, in favour of being able to use stream_select (or any other events API available). It's possible to use the pipe() api to create anonymous pipes owned by a channel, thus raising events is just a write(), possibly conditionally, we can wrap the read end in a normal php stream, and so it can be used by stream_select. here's a demo showing the kind of thing I mean ... As usual, I have no idea how to do this on windows ... there are limits on file descriptors that we would have to manage (only creating pipes for channels which we create a stream for, and with some limit/guardrails that make sense). I don't know the shape of the thing overall, just the basis I wanted to work from when I came to revisit this, and it does need revisiting, events are terrible. Eventually I will get around to this, but it looks like you have the appetite right now :) |
Events::poll()now scans all watched targets once, then sleeps on a process-wide notification condition until a channel or future changes state. This replaces repeated random probing while keeping the public API unchanged; Windows x86 retains polling because pthreads-win32 condition waits hang there.Why: idle polling previously spent about 0.47 CPU-seconds per wall-clock second. The notification-driven implementation reduced that to about 0.01 CPU-seconds, while median wake latency remained about 1.26 ms for 1, 10, and 1,000 targets (including a 1 ms producer delay).
What changed
Verification