Skip to content

Commit

Permalink
chore: add support for grpc kepalive
Browse files Browse the repository at this point in the history
  • Loading branch information
pgautier404 committed Nov 22, 2024
1 parent 4cd8ebd commit 721ba40
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/Cache/Internal/DataGrpcManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ public function __construct(ICredentialProvider $authProvider, IConfiguration $c
if ($forceNewChannel) {
$channelArgs["force_new"] = $forceNewChannel;
}
if ($configuration->getTransportStrategy()->getGrpcConfig()->getKeepAlivePermitWithoutCalls()) {
$channelArgs["grpc.keepalive_permit_without_calls"] =
$configuration->getTransportStrategy()->getGrpcConfig()->getKeepAlivePermitWithoutCalls();
}
if ($configuration->getTransportStrategy()->getGrpcConfig()->getKeepAliveTimeoutMS()) {
$channelArgs["grpc.keepalive_timeout_ms"] =
$configuration->getTransportStrategy()->getGrpcConfig()->getKeepAliveTimeoutMS();
}
if ($configuration->getTransportStrategy()->getGrpcConfig()->getKeepAliveTimeMS()) {
$channelArgs["grpc.keepalive_time_ms"] =
$configuration->getTransportStrategy()->getGrpcConfig()->getKeepAliveTimeMS();
}
$this->channel = new Channel($endpoint, $channelArgs);
$interceptors = [
new AuthorizationInterceptor($authProvider->getAuthToken()),
Expand Down
7 changes: 7 additions & 0 deletions src/Config/Transport/IGrpcConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ public function withForceNewChannel(bool $forceNewChannel) : IGrpcConfiguration;
public function getNumGrpcChannels(): int;

public function withNumGrpcChannels(int $numGrpcChannels): IGrpcConfiguration;

public function getKeepAlivePermitWithoutCalls(): ?int;

public function getKeepAliveTimeoutMS(): ?int;

public function getKeepAliveTimeMS(): ?int;

}
31 changes: 29 additions & 2 deletions src/Config/Transport/StaticGrpcConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,39 @@ class StaticGrpcConfiguration implements IGrpcConfiguration
private ?int $deadlineMilliseconds;
private bool $forceNewChannel;
private int $numGrpcChannels;
private ?int $keepAlivePermitWithoutCalls;
private ?int $keepAliveTimeoutMS;
private ?int $keepAliveTimeMS;

public function __construct(?int $deadlineMilliseconds = null, bool $forceNewChannel = false, int $numGrpcChannels = 1)
{
public function __construct(
?int $deadlineMilliseconds = null,
bool $forceNewChannel = false,
int $numGrpcChannels = 1,
?int $keepAlivePermitWithoutCalls = 0,
?int $keepAliveTimeoutMS = null,
?int $keepAliveTimeMS = null
) {
$this->deadlineMilliseconds = $deadlineMilliseconds;
$this->forceNewChannel = $forceNewChannel;
$this->numGrpcChannels = $numGrpcChannels;
$this->keepAlivePermitWithoutCalls = $keepAlivePermitWithoutCalls;
$this->keepAliveTimeoutMS = $keepAliveTimeoutMS;
$this->keepAliveTimeMS = $keepAliveTimeMS;
}

public function getKeepAlivePermitWithoutCalls(): ?int
{
return $this->keepAlivePermitWithoutCalls;
}

public function getKeepAliveTimeoutMS(): ?int
{
return $this->keepAliveTimeoutMS;
}

public function getKeepAliveTimeMS(): ?int
{
return $this->keepAliveTimeMS;
}

public function getDeadlineMilliseconds(): ?int
Expand Down

0 comments on commit 721ba40

Please sign in to comment.