-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRpcOptions.java
More file actions
312 lines (250 loc) · 9.27 KB
/
RpcOptions.java
File metadata and controls
312 lines (250 loc) · 9.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
* Copyright 2023 Greptime Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.greptime.rpc;
import io.greptime.common.Copiable;
import java.util.concurrent.TimeUnit;
/**
* RPC client options.
*/
public class RpcOptions implements Copiable<RpcOptions> {
private boolean useRpcSharedPool = false;
/**
* RPC request default timeout in milliseconds
* Default: 60000(60s)
*/
private int defaultRpcTimeout = 60000;
/**
* Sets the maximum message size allowed to be received on a channel.
*/
private int maxInboundMessageSize = 256 * 1024 * 1024;
private int flowControlWindow = 256 * 1024 * 1024;
/**
* Set the duration without ongoing RPCs before going to idle mode.
* In idle mode the channel shuts down all connections.
*/
private long idleTimeoutSeconds = TimeUnit.MINUTES.toSeconds(5);
// --- keep-alive options: default will disable keep-alive
/**
* Sets the time without read activity before sending a keep-alive ping.
*/
private long keepAliveTimeSeconds = Long.MAX_VALUE;
/**
* Sets the time waiting for read activity after sending a keep-alive ping.
* If the time expires without any read activity on the connection, the
* connection is considered dead.
*/
private long keepAliveTimeoutSeconds = 3;
/**
* Sets whether keep-alive will be performed when there are no outstanding
* RPC on a connection.
*/
private boolean keepAliveWithoutCalls = false;
// --- keep-alive options: default will disable keep-alive
private LimitKind limitKind = LimitKind.None;
/**
* Initial limit used by the limiter
*/
private int initialLimit = 64;
/**
* Maximum allowable concurrency. Any estimated concurrency will be capped
* at this value
*/
private int maxLimit = 1024;
private int longRttWindow = 100;
/**
* Smoothing factor to limit how aggressively the estimated limit can shrink
* when queuing has been detected.
*/
private double smoothing = 0.2;
/**
* When set to true new calls to the channel will block when the limit has
* been reached instead of failing fast with an UNAVAILABLE status.
*/
private boolean blockOnLimit = false;
private boolean logOnLimitChange = true;
private boolean enableMetricInterceptor = false;
/**
* Set `TlsOptions` to use secure connection between client and server. Set to `null` to use
* plaintext connection instead.
*/
private TlsOptions tlsOptions;
public TlsOptions getTlsOptions() {
return tlsOptions;
}
public void setTlsOptions(TlsOptions tlsOptions) {
this.tlsOptions = tlsOptions;
}
public boolean isUseRpcSharedPool() {
return useRpcSharedPool;
}
public void setUseRpcSharedPool(boolean useRpcSharedPool) {
this.useRpcSharedPool = useRpcSharedPool;
}
public int getDefaultRpcTimeout() {
return defaultRpcTimeout;
}
public void setDefaultRpcTimeout(int defaultRpcTimeout) {
this.defaultRpcTimeout = defaultRpcTimeout;
}
public int getMaxInboundMessageSize() {
return maxInboundMessageSize;
}
public void setMaxInboundMessageSize(int maxInboundMessageSize) {
this.maxInboundMessageSize = maxInboundMessageSize;
}
public int getFlowControlWindow() {
return flowControlWindow;
}
public void setFlowControlWindow(int flowControlWindow) {
this.flowControlWindow = flowControlWindow;
}
public long getIdleTimeoutSeconds() {
return idleTimeoutSeconds;
}
public void setIdleTimeoutSeconds(long idleTimeoutSeconds) {
this.idleTimeoutSeconds = idleTimeoutSeconds;
}
public long getKeepAliveTimeSeconds() {
return keepAliveTimeSeconds;
}
public void setKeepAliveTimeSeconds(long keepAliveTimeSeconds) {
this.keepAliveTimeSeconds = keepAliveTimeSeconds;
}
public long getKeepAliveTimeoutSeconds() {
return keepAliveTimeoutSeconds;
}
public void setKeepAliveTimeoutSeconds(long keepAliveTimeoutSeconds) {
this.keepAliveTimeoutSeconds = keepAliveTimeoutSeconds;
}
public boolean isKeepAliveWithoutCalls() {
return keepAliveWithoutCalls;
}
public void setKeepAliveWithoutCalls(boolean keepAliveWithoutCalls) {
this.keepAliveWithoutCalls = keepAliveWithoutCalls;
}
public LimitKind getLimitKind() {
return limitKind;
}
public void setLimitKind(LimitKind limitKind) {
this.limitKind = limitKind;
}
public int getInitialLimit() {
return initialLimit;
}
public void setInitialLimit(int initialLimit) {
this.initialLimit = initialLimit;
}
public int getMaxLimit() {
return maxLimit;
}
public void setMaxLimit(int maxLimit) {
this.maxLimit = maxLimit;
}
public int getLongRttWindow() {
return longRttWindow;
}
public void setLongRttWindow(int longRttWindow) {
this.longRttWindow = longRttWindow;
}
public double getSmoothing() {
return smoothing;
}
public void setSmoothing(double smoothing) {
this.smoothing = smoothing;
}
public boolean isBlockOnLimit() {
return blockOnLimit;
}
public void setBlockOnLimit(boolean blockOnLimit) {
this.blockOnLimit = blockOnLimit;
}
public boolean isLogOnLimitChange() {
return logOnLimitChange;
}
public void setLogOnLimitChange(boolean logOnLimitChange) {
this.logOnLimitChange = logOnLimitChange;
}
public boolean isEnableMetricInterceptor() {
return enableMetricInterceptor;
}
public void setEnableMetricInterceptor(boolean enableMetricInterceptor) {
this.enableMetricInterceptor = enableMetricInterceptor;
}
@Override
public RpcOptions copy() {
final RpcOptions opts = new RpcOptions();
opts.useRpcSharedPool = this.useRpcSharedPool;
opts.defaultRpcTimeout = this.defaultRpcTimeout;
opts.maxInboundMessageSize = this.maxInboundMessageSize;
opts.flowControlWindow = this.flowControlWindow;
opts.idleTimeoutSeconds = this.idleTimeoutSeconds;
opts.keepAliveTimeSeconds = this.keepAliveTimeSeconds;
opts.keepAliveTimeoutSeconds = this.keepAliveTimeoutSeconds;
opts.keepAliveWithoutCalls = this.keepAliveWithoutCalls;
opts.limitKind = this.limitKind;
opts.initialLimit = this.initialLimit;
opts.maxLimit = this.maxLimit;
opts.longRttWindow = this.longRttWindow;
opts.smoothing = this.smoothing;
opts.blockOnLimit = this.blockOnLimit;
opts.logOnLimitChange = this.logOnLimitChange;
opts.enableMetricInterceptor = this.enableMetricInterceptor;
opts.tlsOptions = this.tlsOptions;
return opts;
}
@Override
public String toString() {
return "RpcOptions{" + "useRpcSharedPool="
+ useRpcSharedPool + ", defaultRpcTimeout="
+ defaultRpcTimeout + ", maxInboundMessageSize="
+ maxInboundMessageSize + ", flowControlWindow="
+ flowControlWindow + ", idleTimeoutSeconds="
+ idleTimeoutSeconds + ", keepAliveTimeSeconds="
+ keepAliveTimeSeconds + ", keepAliveTimeoutSeconds="
+ keepAliveTimeoutSeconds + ", keepAliveWithoutCalls="
+ keepAliveWithoutCalls + ", limitKind="
+ limitKind + ", initialLimit="
+ initialLimit + ", maxLimit="
+ maxLimit + ", longRttWindow="
+ longRttWindow + ", smoothing="
+ smoothing + ", blockOnLimit="
+ blockOnLimit + ", logOnLimitChange="
+ logOnLimitChange + ", enableMetricInterceptor="
+ enableMetricInterceptor + ", tlsOptions="
+ tlsOptions + '}';
}
public static RpcOptions newDefault() {
return new RpcOptions();
}
public enum LimitKind {
/**
* Limiter based on TCP Vegas where the limit increases by alpha if the
* queue_use is small ({@literal <} alpha) and decreases by alpha if
* the queue_use is large ({@literal >} beta).
*/
Vegas,
/**
* Concurrency limit algorithm that adjusts the limit based on the gradient
* of change of the current average RTT and a long term exponentially smoothed
* average RTT. Unlike traditional congestion control algorithms we use average
* instead of minimum since RPC methods can be very bursty due to various
* factors such as non-homogenous request processing complexity as well as a
* wide distribution of data size.
*/
Gradient,
None
}
}