Skip to content

Commit

Permalink
Increase window before reaching 0
Browse files Browse the repository at this point in the history
This should provide better throughput, as stream windows will not have to reach 0 before being increased. Each window should always have at least two frames of space available.
  • Loading branch information
trowski committed Sep 19, 2019
1 parent 827af8f commit 2f47a46
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Connection/Http2Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ final class Http2Connection implements Connection
public const DEFAULT_MAX_FRAME_SIZE = 1 << 14;
public const DEFAULT_WINDOW_SIZE = (1 << 16) - 1;

public const MAX_INCREMENT = (1 << 16) - 1;
private const MINIMUM_WINDOW = (1 << 15) - 1;
private const MAX_INCREMENT = (1 << 16) - 1;

private const HEADER_NAME_REGEX = '/^[\x21-\x40\x5b-\x7e]+$/';

Expand Down Expand Up @@ -627,7 +628,7 @@ private function parser(): \Generator
$body = \substr($buffer, 0, $length - $padding);
$buffer = \substr($buffer, $length);

if ($this->serverWindow <= 0) {
if ($this->serverWindow <= self::MINIMUM_WINDOW) {
$this->serverWindow += self::MAX_INCREMENT;
$this->writeFrame(\pack("N", self::MAX_INCREMENT), self::WINDOW_UPDATE, self::NOFLAG);
}
Expand All @@ -644,15 +645,15 @@ private function parser(): \Generator

$promise = $this->bodyEmitters[$id]->emit($body);

if ($stream->serverWindow <= 0) {
if ($stream->serverWindow <= self::MINIMUM_WINDOW) {
$promise->onResolve(function (?\Throwable $exception) use ($id): void {
if ($exception || !isset($this->streams[$id])) {
return;
}

$stream = $this->streams[$id];

if ($stream->state & Http2Stream::REMOTE_CLOSED) {
if ($stream->state & Http2Stream::REMOTE_CLOSED || $stream->serverWindow > self::MINIMUM_WINDOW) {
return;
}

Expand Down

0 comments on commit 2f47a46

Please sign in to comment.