php / php/php-src

stream_select checking of other streams when read buffered stream present

Offen
#10,177 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Category: Streams Feature
Vorherrschende Sprache
C
Sterne
40.4k
Forks
8.2k
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
96

Beschreibung

Description

This is a result of analysis of the bug #75584 which points out a case where other supplied streams are not checked for read and write if there is a stream that has got buffered data. It means that only streams with buffered data are reported as changed. It is not necessarily a bug as the all data gets eventually processed but the behavior is certainly not optimal and should be optimized.

The optimization can be done by still checking (using select with 0 timeout) of the streams (fds) for write, read without buffered data and exceptional ones when a stream with buffered data is present. The buffered stream(s) would be removed from the checked set passed to select and automatically added to the returned set. In such way only the subset of descriptors would be checked with immediate return to verify if they are ready.

To give an example, following streams are defined

  • $w1 - write stream ready for writing data
  • $w2 - write stream not ready for writing data
  • $r1 - read stream with buffered data available
  • $r2 - read stream without buffered data but data to be read
  • $r3 - read stream without buffered data and no data to be read
  • $e1 - stream with arrived exceptional data

and stream_select is executed as:

$read = [$r1, $r2, $r3];
$write = [$w1, $w2];
$except = [$e1];
stream_select($read, $write, $except, 1);

It will currently set $read array to [$r1] and $write and $except will be empty even though data is available in them. Only until the full buffer is read other streams would show in the arrays.

The optimization would change the behavior and instead of immediately returning after the setting $read with a buffered stream, it would also check the rest of the streams. It means it would basically do following check:

$read = [$r2, $r3];
$write = [$w1, $w2];
$except = [$e1];
stream_select($read, $write, $except, 0);

The result would be then merged and would be like following in this case:

$read = [$r1, $r2];
$write = [$w1];
$except = [$e1];

It should be noted that this approach might result in more syscalls but that seems like something that users should expect as they expect all the descriptors to be checked when calling stream_select.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne am Einstiegspunkt stream_select im PHP-Quellcode und reproduziere das Beispiel mit gepufferten, lesbaren, beschreibbaren und außergewöhnlichen Streams. Verfolge, wie sich der gepufferte Stream auf die Deskriptorprüfungen auswirkt, und verifiziere anschließend, dass alle bereiten Deskriptoren gemeinsam zurückgegeben werden, wobei das angeforderte Timeout-Verhalten erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
c, php
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.