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

gian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git


The following commit(s) were added to refs/heads/master by this push:
     new c19ae13323 Improve direct-memory check on startup. (#13207)
c19ae13323 is described below

commit c19ae13323e74de03fc9b4ede4cbe9a550711dc8
Author: Gian Merlino <[email protected]>
AuthorDate: Tue Oct 11 14:10:25 2022 -0700

    Improve direct-memory check on startup. (#13207)
    
    1) Better support for Java 9+ in RuntimeInfo. This means that in many cases,
       an actual validation can be done.
    
    2) Clearer log message in cases where an actual validation cannot be done.
---
 .../main/java/org/apache/druid/utils/RuntimeInfo.java   |  2 +-
 .../test/java/org/apache/druid/utils/JvmUtilsTest.java  | 14 +++-----------
 .../org/apache/druid/guice/BrokerProcessingModule.java  | 17 +++++++++++------
 3 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/core/src/main/java/org/apache/druid/utils/RuntimeInfo.java 
b/core/src/main/java/org/apache/druid/utils/RuntimeInfo.java
index 1dba77d57d..c8dadfd44d 100644
--- a/core/src/main/java/org/apache/druid/utils/RuntimeInfo.java
+++ b/core/src/main/java/org/apache/druid/utils/RuntimeInfo.java
@@ -48,7 +48,7 @@ public class RuntimeInfo
   public long getDirectMemorySizeBytes()
   {
     try {
-      Class<?> vmClass = Class.forName("sun.misc.VM");
+      Class<?> vmClass = Class.forName(JvmUtils.majorVersion() >= 9 ? 
"jdk.internal.misc.VM" : "sun.misc.VM");
       Object maxDirectMemoryObj = 
vmClass.getMethod("maxDirectMemory").invoke(null);
 
       if (maxDirectMemoryObj == null || !(maxDirectMemoryObj instanceof 
Number)) {
diff --git a/core/src/test/java/org/apache/druid/utils/JvmUtilsTest.java 
b/core/src/test/java/org/apache/druid/utils/JvmUtilsTest.java
index 6136b7a094..225c5c5230 100644
--- a/core/src/test/java/org/apache/druid/utils/JvmUtilsTest.java
+++ b/core/src/test/java/org/apache/druid/utils/JvmUtilsTest.java
@@ -31,18 +31,10 @@ import java.util.List;
 public class JvmUtilsTest
 {
   @Test
-  public void testgetMaxDirectMemory()
+  public void testGetMaxDirectMemory()
   {
-    try {
-      long maxMemory = JvmUtils.getRuntimeInfo().getDirectMemorySizeBytes();
-      Assert.assertTrue((maxMemory > 0));
-    }
-    catch (UnsupportedOperationException expected) {
-      Assert.assertTrue(true);
-    }
-    catch (RuntimeException expected) {
-      Assert.assertTrue(true);
-    }
+    long maxMemory = JvmUtils.getRuntimeInfo().getDirectMemorySizeBytes();
+    Assert.assertTrue((maxMemory > 0));
   }
 
   @Test
diff --git 
a/server/src/main/java/org/apache/druid/guice/BrokerProcessingModule.java 
b/server/src/main/java/org/apache/druid/guice/BrokerProcessingModule.java
index d2273ba9a5..d5f18dd178 100644
--- a/server/src/main/java/org/apache/druid/guice/BrokerProcessingModule.java
+++ b/server/src/main/java/org/apache/druid/guice/BrokerProcessingModule.java
@@ -153,10 +153,11 @@ public class BrokerProcessingModule implements Module
 
   private void verifyDirectMemory(DruidProcessingConfig config)
   {
+    final long memoryNeeded = (long) config.intermediateComputeSizeBytes() *
+                              (config.getNumMergeBuffers() + 1);
+
     try {
       final long maxDirectMemory = 
JvmUtils.getRuntimeInfo().getDirectMemorySizeBytes();
-      final long memoryNeeded = (long) config.intermediateComputeSizeBytes() *
-                                (config.getNumMergeBuffers() + 1);
 
       if (maxDirectMemory < memoryNeeded) {
         throw new ProvisionException(
@@ -174,10 +175,14 @@ public class BrokerProcessingModule implements Module
     catch (UnsupportedOperationException e) {
       log.debug("Checking for direct memory size is not support on this 
platform: %s", e);
       log.info(
-          "Unable to determine max direct memory size. If 
druid.processing.buffer.sizeBytes is explicitly configured, "
-          + "then make sure to set -XX:MaxDirectMemorySize to at least 
\"druid.processing.buffer.sizeBytes * "
-          + "(druid.processing.numMergeBuffers[%,d] + 1)\", "
-          + "or else set -XX:MaxDirectMemorySize to at least 25%% of maximum 
jvm heap size.",
+          "Your memory settings require at least %,d bytes of direct memory. "
+          + "Your machine must have at least this much memory available, and 
your JVM "
+          + "-XX:MaxDirectMemorySize parameter must be at least this high. "
+          + "If it is, you may safely ignore this message. "
+          + "Otherwise, consider adjusting your memory settings. "
+          + "Calculation: druid.processing.buffer.sizeBytes[%,d] * 
(druid.processing.numMergeBuffers[%,d] + 1).",
+          memoryNeeded,
+          config.intermediateComputeSizeBytes(),
           config.getNumMergeBuffers()
       );
     }


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

Reply via email to