Skip to content

Commit 352dd1d

Browse files
Rashmi Makhejameta-codesync[bot]
authored andcommitted
Add Thrift Client config and use it to disable stream 16KB limit
Summary: - Create a new class `ThriftClientConfig` to set custom RPC configurations for Thrift Hack Clients that are not part of RPC Options. - Use this new config to override Streaming buffer policy as described in D81055765 - Use the override in StreamingTestScript Reviewed By: tlj77 Differential Revision: D83917740 fbshipit-source-id: ad8894f57ae1c5d55295a3f24ecc330d9e11d530
1 parent 80d3a48 commit 352dd1d

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

third-party/thrift/src/thrift/lib/hack/src/ThriftClientBase.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ abstract class ThriftClientBase implements IThriftClient {
3333
protected TClientAsyncHandler $asyncHandler_;
3434
protected TClientEventHandler $eventHandler_;
3535
protected ?RpcOptions $options_;
36+
protected ?ThriftClientConfig $config_;
3637

3738
protected int $seqid_ = 0;
3839
abstract const string THRIFT_SVC_NAME;
@@ -122,6 +123,13 @@ public function onceWithOptions(RpcOptions $rpc_options)[write_props]: this {
122123
return $this;
123124
}
124125

126+
public function setThriftClientConfig(
127+
ThriftClientConfig $config,
128+
)[write_props]: this {
129+
$this->config_ = $config;
130+
return $this;
131+
}
132+
125133
protected function getAndResetOptions()[write_props]: ?RpcOptions {
126134
$options = $this->options_;
127135
$this->options_ = null;
@@ -395,6 +403,10 @@ class<TStreamResponseType> $stream_response_type,
395403
$out_transport->resetBuffer();
396404
list($result_msg, $_read_headers, $stream) =
397405
await $channel->genSendRequestStreamResponse($rpc_options, $msg);
406+
$disable16kblimit = $this->config_?->getStreamDisable16KBLimit() ?? false;
407+
if ($disable16kblimit) {
408+
$stream->disable16KBBufferingPolicy();
409+
}
398410

399411
$stream_gen = $stream->gen<TStreamType>(
400412
ThriftStreamingSerializationHelpers::decodeStreamHelper(
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?hh
2+
/*
3+
* Copyright (c) Meta Platforms, Inc. and affiliates.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
// @oss-enable: use namespace FlibSL\{C, Math, Str, Vec};
20+
21+
// Use this to control hack language specific configs for Thrift Client
22+
final class ThriftClientConfig {
23+
/**
24+
* For streaming, default behavior is to send more credits when client has
25+
* consumed either chunkBufferSize/2 payloads or 16KB bytes.
26+
*
27+
* When all payloads are close to 16KB, this means credit is sent after
28+
* every payload. In such cases, clients can choose to disable 16KB limit
29+
* and only send credits after chunkBufferSize/2 payloads are consumed.
30+
*/
31+
private bool $streamDisable16KBLimit = false;
32+
public function __construct()[] {}
33+
34+
public function setStreamDisable16KBLimit(bool $val)[write_props]: this {
35+
$this->streamDisable16KBLimit = $val;
36+
return $this;
37+
}
38+
39+
public function getStreamDisable16KBLimit()[]: bool {
40+
return $this->streamDisable16KBLimit;
41+
}
42+
}

0 commit comments

Comments
 (0)