Io\Poll\Context::wait() is O(n) in the number of level-triggered Read watchers
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Ambito
- backend, operating-systems, performance
Direzione di ricerca
Start with the cited loop in ext/standard/io_poll.c and trace how php_stream_fill_read_buffer() and php_io_poll_stream_notify_close() use php_stream.poll_watchers. Reproduce the benchmark with level-triggered and edge-triggered Read watchers, then inspect the relevant I/O poll tests. Done means idle level-triggered waits no longer scale with the total watcher count while preserving the GH-23948 behavior and ABI.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
Since #24017 (fix for GH-23948), Io\Poll\Context::wait() takes time proportional to the number of registered level-triggered Read watchers, even when none of them is ready. Before each backend wait it iterates over every watcher of the context to look for data in the stream read buffer:
The following code:
<?php
use Io\Poll\{Backend, Context, Event};
use Time\Duration;
foreach ([100, 1000, 10000, 20000] as $n) {
foreach (['level' => [Event::Read], 'edge' => [Event::Read, Event::EdgeTriggered]] as $mode => $events) {
$ctx = new Context(Backend::Epoll);
$pairs = [];
for ($i = 0; $i < $n; $i++) {
$pairs[] = $pair = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
$ctx->add(new StreamPollHandle($pair[0]), $events);
}
$zero = Duration::fromSeconds(0);
$start = hrtime(true);
for ($i = 0; $i < 5000; $i++) {
$ctx->wait($zero);
}
printf("%-5s n=%-6d %8.2f us per wait()\n", $mode, $n, (hrtime(true) - $start) / 5000 / 1e3);
unset($ctx);
foreach ($pairs as [$a, $b]) {
fclose($a);
fclose($b);
}
}
}
Resulted in this output (needs ulimit -n above 40000):
level n=100 1.19 us per wait()
edge n=100 0.38 us per wait()
level n=1000 8.77 us per wait()
edge n=1000 0.37 us per wait()
level n=10000 295.23 us per wait()
edge n=10000 0.36 us per wait()
level n=20000 933.23 us per wait()
edge n=20000 0.40 us per wait()
Expected: the level rows stay close to the edge rows, since no handle is ready and the epoll backend is O(ready events). maxEvents makes no difference.
Impact on an event loop: a TCP echo server (32 active ping-pong connections plus N idle ones, loopback, 4 CPUs) on revolt/event-loop 1.1.0-RC1 IoPollDriver drops from about 100k round trips/s with 1,000 idle connections to 56k with 10,000 and 27k with 20,000. Server CPU per round trip goes from 9.9 µs to 37.5 µs. The same server on EvDriver (ext-ev) stays at about 105k round trips/s and 9.4 µs at every size. Level-triggered Read is the default and what the event loop drivers use, so they all pay this cost on every tick.
A possible direction that keeps the GH-23948 behaviour without breaking ABI: a stream's read buffer only grows in php_stream_fill_read_buffer(), and php_stream already has poll_watchers (used by php_io_poll_stream_notify_close()). That function could notify the stream's watchers when the buffer is non-empty, queueing them on their context. wait() would then check only the queued watchers, dropping those whose buffer has been drained, instead of every watcher.
PHP Version
PHP 8.6.0 (cli) (built: Nov 19 2026 15:18:16) (ZTS)
Official php:8.6-cli-alpine Docker image.
Operating System
Alpine Linux 3.24 (Docker), host kernel Linux 7.0 x86_64
- Lingua principale
- C
- Stelle
- 41.8k
- Fork
- 8.6k
- Merge medio
- 2g 15h
- PR unite (30g)
- 125
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di php/php-src
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
ext/openssl: 8.2.31+/8.3.31+ fail to build against OpenSSL 1.0.2 (ASN1_STRING_get0_data in xp_ssl.c)ApertaExtension: openssl Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
php/php-src#25402 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
php/php-src#25397 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
SNMP accepts malformed remote portsForse già presa @somethingwithproof l’ha presa 21 giorni fa. Aperta
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
php/php-src#25137 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Bug Status: Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
ZIP/ZIPS decode dereferences NULL when the cached libdeflate decompressor can't be allocated (3.5 regression)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
AcademySoftwareFoundation/openexr#2884 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
python-pillow/Pillow#10590 ·
I maintainer di solito rispondono entro 1 giorno
-
status: needs-triage type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
openwrt/packages#31407 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno