ankuriitg commented on a change in pull request #23278: [SPARK-24920][Core] 
Allow sharing Netty's memory pool allocators
URL: https://github.com/apache/spark/pull/23278#discussion_r240792081
 
 

 ##########
 File path: 
common/network-common/src/main/java/org/apache/spark/network/util/NettyUtils.java
 ##########
 @@ -95,6 +111,38 @@ public static String getRemoteAddress(Channel channel) {
     return "<unknown remote>";
   }
 
+  /**
+   * Returns the default number of threads for both the Netty client and 
server thread pools.
+   * If numUsableCores is 0, we will use Runtime get an approximate number of 
available cores.
+   */
+  public static int defaultNumThreads(int numUsableCores) {
+    final int availableCores;
+    if (numUsableCores > 0) {
+      availableCores = numUsableCores;
+    } else {
+      availableCores = Runtime.getRuntime().availableProcessors();
+    }
+    return Math.min(availableCores, MAX_DEFAULT_NETTY_THREADS);
+  }
+
+  /**
+   * Returns the lazily created shared pooled ByteBuf allocator for the 
specified allowCache
+   * parameter value.
+   */
+  public static synchronized PooledByteBufAllocator 
getSharedPooledByteBufAllocator(
+      boolean allowDirectBufs,
+      boolean allowCache) {
+    final int index = allowCache ? 0 : 1;
 
 Review comment:
   I don't think that you need to change createPooledByteBufAllocator if you 
change this method. allowCache is used to determine whether to create a pool 
with or without cache in createPooledByteBufAllocator. This is different from 
getSharedPooledByteBufAllocator which is using allowCache to determine this 
plus, it is also using allowCache to determine whether to return a 
pooledAllocator for a client or a server.
   
   You may still want to keep this change if allowCache is the only thing that 
distinguishes the two pooled allocators but if it is not then it may be better 
to create another variable.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to