Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  add possibility to configure the max http concurrency
  • Loading branch information
Baptouuuu committed Feb 11, 2023
2 parents 9efee2b + 6716060 commit 4d596ad
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 3.6.0 - 2023-02-11

### Added

- `Innmind\OperatingSystem\Config::limitHttpConcurrencyTo()`

### Changed

- Requires `innmind/http-transport:~6.4`

## 3.5.0 - 2023-01-29

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"innmind/server-control": "~5.0",
"innmind/filesystem": "~6.2",
"innmind/socket": "~6.0",
"innmind/http-transport": "~6.3",
"innmind/http-transport": "~6.4",
"innmind/time-warp": "~3.0",
"innmind/signals": "~3.0",
"innmind/file-watch": "~3.1",
Expand Down
38 changes: 38 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,41 @@
Capabilities,
Streams,
};
use Innmind\Immutable\Maybe;

final class Config
{
private CaseSensitivity $caseSensitivity;
private Capabilities $streamCapabilities;
private EnvironmentPath $path;
/** @var Maybe<positive-int> */
private Maybe $maxHttpConcurrency;

/**
* @param Maybe<positive-int> $maxHttpConcurrency
*/
private function __construct(
CaseSensitivity $caseSensitivity,
Capabilities $streamCapabilities,
EnvironmentPath $path,
Maybe $maxHttpConcurrency,
) {
$this->caseSensitivity = $caseSensitivity;
$this->streamCapabilities = $streamCapabilities;
$this->path = $path;
$this->maxHttpConcurrency = $maxHttpConcurrency;
}

public static function of(): self
{
/** @var Maybe<positive-int> */
$maxHttpConcurrency = Maybe::nothing();

return new self(
CaseSensitivity::sensitive,
Streams::fromAmbientAuthority(),
EnvironmentPath::of(\getenv('PATH') ?: ''),
$maxHttpConcurrency,
);
}

Expand All @@ -44,6 +56,7 @@ public function caseInsensitiveFilesystem(): self
CaseSensitivity::insensitive,
$this->streamCapabilities,
$this->path,
$this->maxHttpConcurrency,
);
}

Expand All @@ -56,6 +69,7 @@ public function useStreamCapabilities(Capabilities $capabilities): self
$this->caseSensitivity,
$capabilities,
$this->path,
$this->maxHttpConcurrency,
);
}

Expand All @@ -68,6 +82,20 @@ public function withEnvironmentPath(EnvironmentPath $path): self
$this->caseSensitivity,
$this->streamCapabilities,
$path,
$this->maxHttpConcurrency,
);
}

/**
* @param positive-int $max
*/
public function limitHttpConcurrencyTo(int $max): self
{
return new self(
$this->caseSensitivity,
$this->streamCapabilities,
$this->path,
Maybe::just($max),
);
}

Expand All @@ -94,4 +122,14 @@ public function environmentPath(): EnvironmentPath
{
return $this->path;
}

/**
* @internal
*
* @return Maybe<positive-int>
*/
public function maxHttpConcurrency(): Maybe
{
return $this->maxHttpConcurrency;
}
}
11 changes: 10 additions & 1 deletion src/Remote/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,20 @@ public function socket(Transport $transport, Authority $authority): Maybe

public function http(): HttpTransport
{
return $this->http ??= Curl::of(
if ($this->http) {
return $this->http;
}

$http = Curl::of(
$this->clock,
new Chunk,
$this->config->streamCapabilities(),
);

return $this->http = $this->config->maxHttpConcurrency()->match(
static fn($max) => $http->maxConcurrency($max),
static fn() => $http,
);
}

public function sql(Url $server): Connection
Expand Down

0 comments on commit 4d596ad

Please sign in to comment.