Skip to content

Commit 503fc24

Browse files
committed
Allocator related tuning
Signed-off-by: Rishabh Maurya <[email protected]>
1 parent 3f1bde2 commit 503fc24

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

plugins/arrow-flight-rpc/src/main/java/org/opensearch/arrow/flight/transport/FlightTransport.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ class FlightTransport extends TcpTransport {
9494
private final ExecutorService clientExecutor;
9595

9696
private final ThreadPool threadPool;
97-
private BufferAllocator allocator;
97+
private RootAllocator rootAllocator;
98+
private BufferAllocator serverAllocator;
99+
private BufferAllocator clientAllocator;
100+
98101
private final NamedWriteableRegistry namedWriteableRegistry;
99102
private final FlightStatsCollector statsCollector;
100103
private final FlightTransportConfig config = new FlightTransportConfig();
@@ -136,12 +139,14 @@ public FlightTransport(
136139
protected void doStart() {
137140
boolean success = false;
138141
try {
139-
allocator = AccessController.doPrivileged((PrivilegedAction<BufferAllocator>) () -> new RootAllocator(Integer.MAX_VALUE));
142+
rootAllocator = AccessController.doPrivileged((PrivilegedAction<RootAllocator>) () -> new RootAllocator(Integer.MAX_VALUE));
143+
serverAllocator = rootAllocator.newChildAllocator("server", 0, rootAllocator.getLimit());
144+
clientAllocator = rootAllocator.newChildAllocator("client", 0, rootAllocator.getLimit());
140145
if (statsCollector != null) {
141-
statsCollector.setBufferAllocator(allocator);
146+
statsCollector.setBufferAllocator(rootAllocator);
142147
statsCollector.setThreadPool(threadPool);
143148
}
144-
flightProducer = new ArrowFlightProducer(this, allocator, SERVER_HEADER_KEY, statsCollector);
149+
flightProducer = new ArrowFlightProducer(this, rootAllocator, SERVER_HEADER_KEY, statsCollector);
145150
bindServer();
146151
success = true;
147152
if (statsCollector != null) {
@@ -215,7 +220,7 @@ private List<InetSocketAddress> bindToPort(InetAddress[] hostAddresses) {
215220
// Create single FlightServer with all locations
216221
ServerHeaderMiddleware.Factory factory = new ServerHeaderMiddleware.Factory();
217222
OSFlightServer.Builder builder = OSFlightServer.builder()
218-
.allocator(allocator.newChildAllocator("server", 0, Long.MAX_VALUE))
223+
.allocator(serverAllocator)
219224
.producer(flightProducer)
220225
.sslContext(sslContextProvider != null ? sslContextProvider.getServerSslContext() : null)
221226
.channelType(ServerConfig.serverChannelType())
@@ -256,11 +261,13 @@ protected void stopInternal() {
256261
flightServer.close();
257262
flightServer = null;
258263
}
264+
serverAllocator.close();
259265
for (ClientHolder holder : flightClients.values()) {
260266
holder.flightClient().close();
261267
}
262-
allocator.close();
263268
flightClients.clear();
269+
clientAllocator.close();
270+
rootAllocator.close();
264271
gracefullyShutdownELG(bossEventLoopGroup, "os-grpc-boss-ELG");
265272
gracefullyShutdownELG(workerEventLoopGroup, "os-grpc-worker-ELG");
266273
if (statsCollector != null) {
@@ -297,7 +304,7 @@ protected TcpChannel initiateChannel(DiscoveryNode node) throws IOException {
297304
ClientHeaderMiddleware.Factory factory = new ClientHeaderMiddleware.Factory(context, getVersion());
298305
FlightClient client = OSFlightClient.builder()
299306
// TODO configure initial and max reservation setting per client
300-
.allocator(allocator.newChildAllocator("client-" + nodeId, 0, Long.MAX_VALUE))
307+
.allocator(clientAllocator)
301308
.location(location)
302309
.channelType(ServerConfig.clientChannelType())
303310
.eventLoopGroup(workerEventLoopGroup)
@@ -307,7 +314,6 @@ protected TcpChannel initiateChannel(DiscoveryNode node) throws IOException {
307314
.build();
308315
return new ClientHolder(location, client, context);
309316
});
310-
311317
FlightClientChannel channel = new FlightClientChannel(
312318
boundAddress,
313319
holder.flightClient(),

0 commit comments

Comments
 (0)