You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uniffle.apache.org by ri...@apache.org on 2024/09/05 09:09:41 UTC
(incubator-uniffle) branch master updated: [#2096] fix(client): Share Netty's memory allocators in gRPC (#2098)
This is an automated email from the ASF dual-hosted git repository.
rickyma pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git
The following commit(s) were added to refs/heads/master by this push:
new 11dd32628 [#2096] fix(client): Share Netty's memory allocators in gRPC (#2098)
11dd32628 is described below
commit 11dd326286132bbc0a168b94b0151870c136b4bd
Author: zhengchenyu <zh...@163.com>
AuthorDate: Thu Sep 5 17:09:35 2024 +0800
[#2096] fix(client): Share Netty's memory allocators in gRPC (#2098)
### What changes were proposed in this pull request?
Use a static allocator for GrpcClient
### Why are the changes needed?
Fix: #2096
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Tested in real cluster.
---
.../apache/uniffle/common/util/GrpcNettyUtils.java | 12 +++++++++
.../uniffle/client/impl/grpc/GrpcClient.java | 8 +-----
.../client/impl/grpc/ShuffleServerGrpcClient.java | 31 ++++++----------------
.../impl/grpc/ShuffleServerGrpcNettyClient.java | 21 +--------------
4 files changed, 22 insertions(+), 50 deletions(-)
diff --git a/common/src/main/java/org/apache/uniffle/common/util/GrpcNettyUtils.java b/common/src/main/java/org/apache/uniffle/common/util/GrpcNettyUtils.java
index 93a7949d7..9060a6b1f 100644
--- a/common/src/main/java/org/apache/uniffle/common/util/GrpcNettyUtils.java
+++ b/common/src/main/java/org/apache/uniffle/common/util/GrpcNettyUtils.java
@@ -17,10 +17,14 @@
package org.apache.uniffle.common.util;
+import io.grpc.netty.shaded.io.netty.buffer.ByteBufAllocator;
import io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator;
import io.grpc.netty.shaded.io.netty.util.internal.PlatformDependent;
public class GrpcNettyUtils {
+
+ private static volatile PooledByteBufAllocator allocator;
+
public static PooledByteBufAllocator createPooledByteBufAllocator(
boolean preferDirect, int numCores, int pageSize, int maxOrder, int smallCacheSize) {
return createPooledByteBufAllocator(
@@ -64,4 +68,12 @@ public class GrpcNettyUtils {
return createPooledByteBufAllocator(
preferDirect, true, numCores, pageSize, maxOrder, smallCacheSize, -1);
}
+
+ public static synchronized ByteBufAllocator getSharedPooledByteBufAllocator(
+ int pageSize, int maxOrder, int smallCacheSize) {
+ if (allocator == null) {
+ allocator = createPooledByteBufAllocator(true, 0, pageSize, maxOrder, smallCacheSize);
+ }
+ return allocator;
+ }
}
diff --git a/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/GrpcClient.java b/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/GrpcClient.java
index 3539b9e90..2f5b09c78 100644
--- a/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/GrpcClient.java
+++ b/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/GrpcClient.java
@@ -21,7 +21,6 @@ import java.util.concurrent.TimeUnit;
import io.grpc.ManagedChannel;
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
-import io.grpc.netty.shaded.io.netty.buffer.ByteBufAllocator;
import io.grpc.netty.shaded.io.netty.channel.ChannelOption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,7 +57,7 @@ public abstract class GrpcClient {
NettyChannelBuilder.forAddress(host, port)
.withOption(
ChannelOption.ALLOCATOR,
- createByteBufAllocator(pageSize, maxOrder, smallCacheSize));
+ GrpcNettyUtils.getSharedPooledByteBufAllocator(pageSize, maxOrder, smallCacheSize));
if (usePlaintext) {
channelBuilder.usePlaintext();
@@ -76,11 +75,6 @@ public abstract class GrpcClient {
this.channel = channel;
}
- protected ByteBufAllocator createByteBufAllocator(
- int pageSize, int maxOrder, int smallCacheSize) {
- return GrpcNettyUtils.createPooledByteBufAllocator(true, 0, 0, 0, 0);
- }
-
public void close() {
try {
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
diff --git a/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/ShuffleServerGrpcClient.java b/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/ShuffleServerGrpcClient.java
index cc645172c..246ae3e37 100644
--- a/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/ShuffleServerGrpcClient.java
+++ b/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/ShuffleServerGrpcClient.java
@@ -144,9 +144,10 @@ public class ShuffleServerGrpcClient extends GrpcClient implements ShuffleServer
port,
RssClientConf.RPC_MAX_ATTEMPTS.defaultValue(),
RssClientConf.RPC_TIMEOUT_MS.defaultValue(),
- RssClientConf.RPC_NETTY_PAGE_SIZE.defaultValue(),
- RssClientConf.RPC_NETTY_MAX_ORDER.defaultValue(),
- RssClientConf.RPC_NETTY_SMALL_CACHE_SIZE.defaultValue());
+ true,
+ 0,
+ 0,
+ 0);
}
public ShuffleServerGrpcClient(RssConf rssConf, String host, int port) {
@@ -159,26 +160,10 @@ public class ShuffleServerGrpcClient extends GrpcClient implements ShuffleServer
rssConf == null
? RssClientConf.RPC_TIMEOUT_MS.defaultValue()
: rssConf.getLong(RssClientConf.RPC_TIMEOUT_MS),
- rssConf == null
- ? RssClientConf.RPC_NETTY_PAGE_SIZE.defaultValue()
- : rssConf.getInteger(RssClientConf.RPC_NETTY_PAGE_SIZE),
- rssConf == null
- ? RssClientConf.RPC_NETTY_MAX_ORDER.defaultValue()
- : rssConf.getInteger(RssClientConf.RPC_NETTY_MAX_ORDER),
- rssConf == null
- ? RssClientConf.RPC_NETTY_SMALL_CACHE_SIZE.defaultValue()
- : rssConf.getInteger(RssClientConf.RPC_NETTY_SMALL_CACHE_SIZE));
- }
-
- public ShuffleServerGrpcClient(
- String host,
- int port,
- int maxRetryAttempts,
- long rpcTimeoutMs,
- int pageSize,
- int maxOrder,
- int smallCacheSize) {
- this(host, port, maxRetryAttempts, rpcTimeoutMs, true, pageSize, maxOrder, smallCacheSize);
+ true,
+ 0,
+ 0,
+ 0);
}
public ShuffleServerGrpcClient(
diff --git a/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/ShuffleServerGrpcNettyClient.java b/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/ShuffleServerGrpcNettyClient.java
index 5d3303aac..c2fde9176 100644
--- a/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/ShuffleServerGrpcNettyClient.java
+++ b/internal-client/src/main/java/org/apache/uniffle/client/impl/grpc/ShuffleServerGrpcNettyClient.java
@@ -24,7 +24,6 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import com.google.common.annotations.VisibleForTesting;
-import io.grpc.netty.shaded.io.netty.buffer.ByteBufAllocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,7 +54,6 @@ import org.apache.uniffle.common.netty.protocol.GetMemoryShuffleDataResponse;
import org.apache.uniffle.common.netty.protocol.RpcResponse;
import org.apache.uniffle.common.netty.protocol.SendShuffleDataRequest;
import org.apache.uniffle.common.rpc.StatusCode;
-import org.apache.uniffle.common.util.GrpcNettyUtils;
import org.apache.uniffle.common.util.RetryUtils;
public class ShuffleServerGrpcNettyClient extends ShuffleServerGrpcClient {
@@ -101,29 +99,12 @@ public class ShuffleServerGrpcNettyClient extends ShuffleServerGrpcClient {
int pageSize,
int maxOrder,
int smallCacheSize) {
- super(host, grpcPort, maxRetryAttempts, rpcTimeoutMs, pageSize, maxOrder, smallCacheSize);
+ super(host, grpcPort, maxRetryAttempts, rpcTimeoutMs, true, pageSize, maxOrder, smallCacheSize);
this.nettyPort = nettyPort;
TransportContext transportContext = new TransportContext(new TransportConf(rssConf));
this.clientFactory = new TransportClientFactory(transportContext);
}
- @Override
- protected ByteBufAllocator createByteBufAllocator(
- int pageSize, int maxOrder, int smallCacheSize) {
- LOG.info(
- "ShuffleServerGrpcNettyClient is initialized - host:{}, gRPC port:{}, netty port:{}, maxRetryAttempts:{}, usePlaintext:{}, pageSize:{}, maxOrder:{}, smallCacheSize={}",
- host,
- port,
- nettyPort,
- maxRetryAttempts,
- usePlaintext,
- pageSize,
- maxOrder,
- smallCacheSize);
- return GrpcNettyUtils.createPooledByteBufAllocatorWithSmallCacheOnly(
- true, 0, pageSize, maxOrder, smallCacheSize);
- }
-
@Override
public String getClientInfo() {
return "ShuffleServerGrpcNettyClient for host["