This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 21c9798  RATIS-534. Warn that the netty useCacheForAllThreads feature 
may cause JVM GC pauses.  Contributed by Lokesh Jain
21c9798 is described below

commit 21c979895c8e9f12ba6b88717de5511e46eece2c
Author: Tsz Wo Nicholas Sze <[email protected]>
AuthorDate: Thu May 16 13:59:07 2019 -0700

    RATIS-534. Warn that the netty useCacheForAllThreads feature may cause JVM 
GC pauses.  Contributed by Lokesh Jain
---
 .../java/org/apache/ratis/grpc/GrpcFactory.java    | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcFactory.java 
b/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcFactory.java
index d4946e7..527e1b1 100644
--- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcFactory.java
+++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/GrpcFactory.java
@@ -27,8 +27,28 @@ import org.apache.ratis.protocol.ClientId;
 import org.apache.ratis.rpc.SupportedRpcType;
 import org.apache.ratis.server.RaftServer;
 import org.apache.ratis.server.impl.*;
+import org.apache.ratis.thirdparty.io.netty.buffer.PooledByteBufAllocator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.function.Consumer;
 
 public class GrpcFactory implements ServerFactory, ClientFactory {
+
+  public static final Logger LOG = LoggerFactory.getLogger(GrpcFactory.class);
+
+  private void 
checkPooledByteBufAllocatorUseCacheForAllThreads(Consumer<String> log) {
+    final String name = "useCacheForAllThreads";
+    final String key = "org.apache.ratis.thirdparty.io.netty.allocator." + 
name;
+    final boolean value = 
PooledByteBufAllocator.defaultUseCacheForAllThreads();
+    if (value) {
+      log.accept("PERFORMANCE WARNING: " + name + " is " + value
+          + " that may cause Netty to create a lot garbage objects and, as a 
result, trigger GC.\n"
+          + "\tIt is recommended to disable " + name + " by setting -D" + key
+          + "=" + !value + " in command line.");
+    }
+  }
+
   private final GrpcTlsConfig tlsConfig;
 
   public static Parameters newRaftParameters(GrpcTlsConfig conf) {
@@ -62,6 +82,7 @@ public class GrpcFactory implements ServerFactory, 
ClientFactory {
 
   @Override
   public GrpcService newRaftServerRpc(RaftServer server) {
+    checkPooledByteBufAllocatorUseCacheForAllThreads(LOG::info);
     return GrpcService.newBuilder()
         .setServer(server)
         .setTlsConfig(tlsConfig)
@@ -70,6 +91,7 @@ public class GrpcFactory implements ServerFactory, 
ClientFactory {
 
   @Override
   public GrpcClientRpc newRaftClientRpc(ClientId clientId, RaftProperties 
properties) {
+    checkPooledByteBufAllocatorUseCacheForAllThreads(LOG::debug);
     return new GrpcClientRpc(clientId, properties, getTlsConfig());
   }
 }

Reply via email to