nifi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tpa...@apache.org
Subject [nifi] branch main updated: NIFI-8642 Select the default Old Gen Memory Pool for Memory Reporting Task
Date Fri, 11 Jun 2021 12:08:20 GMT
This is an automated email from the ASF dual-hosted git repository.

tpalfy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new d7a8d27  NIFI-8642 Select the default Old Gen Memory Pool for Memory Reporting Task
d7a8d27 is described below

commit d7a8d275c96040627dd357fa76ba4a8276df8682
Author: Timea Barna <timea.barna@gmail.com>
AuthorDate: Wed Jun 2 08:52:48 2021 +0200

    NIFI-8642 Select the default Old Gen Memory Pool for Memory Reporting Task
    
    This closes #5115.
    
    Signed-off-by: Tamas Palfy <tamas.bertalan.palfy@gmail.com>
---
 .../org/apache/nifi/controller/MonitorMemory.java   | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java
b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java
index c611375..6bfd8e6 100644
--- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java
+++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-reporting-tasks/src/main/java/org/apache/nifi/controller/MonitorMemory.java
@@ -36,11 +36,11 @@ import java.lang.management.ManagementFactory;
 import java.lang.management.MemoryPoolMXBean;
 import java.lang.management.MemoryUsage;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Pattern;
-import java.util.stream.Collectors;
 
 /**
  * Reporting task used to monitor usage of memory after Garbage Collection has
@@ -90,15 +90,23 @@ import java.util.stream.Collectors;
         + " that the memory pool is exceeding this threshold.")
 public class MonitorMemory extends AbstractReportingTask {
 
+    private static final List<String> GC_OLD_GEN_POOLS = Collections.unmodifiableList(Arrays.asList("Tenured
Gen", "PS Old Gen", "G1 Old Gen", "CMS Old Gen", "ZHeap"));
     private static final AllowableValue[] memPoolAllowableValues;
+    private static String defaultMemoryPool;
 
     static {
         // Only allow memory pool beans that support usage thresholds, otherwise we wouldn't
report anything anyway
-        List<MemoryPoolMXBean> memoryPoolBeans = ManagementFactory.getMemoryPoolMXBeans().stream().filter(MemoryPoolMXBean::isUsageThresholdSupported).collect(Collectors.toList());
-        memPoolAllowableValues = new AllowableValue[memoryPoolBeans.size()];
-        for (int i = 0; i < memPoolAllowableValues.length; i++) {
-            memPoolAllowableValues[i] = new AllowableValue(memoryPoolBeans.get(i).getName());
-        }
+        memPoolAllowableValues = ManagementFactory.getMemoryPoolMXBeans()
+                .stream()
+                .filter(MemoryPoolMXBean::isUsageThresholdSupported)
+                .map(MemoryPoolMXBean::getName)
+                .map(AllowableValue::new)
+                .toArray(AllowableValue[]::new);
+        defaultMemoryPool = Arrays.stream(memPoolAllowableValues)
+                .map(AllowableValue::getValue)
+                .filter(GC_OLD_GEN_POOLS::contains)
+                .findFirst()
+                .orElse(null);
     }
 
     public static final PropertyDescriptor MEMORY_POOL_PROPERTY = new PropertyDescriptor.Builder()
@@ -110,6 +118,7 @@ public class MonitorMemory extends AbstractReportingTask {
                     + " running host platform and JVM")
             .required(true)
             .allowableValues(memPoolAllowableValues)
+            .defaultValue(defaultMemoryPool)
             .build();
     public static final PropertyDescriptor THRESHOLD_PROPERTY = new PropertyDescriptor.Builder()
             .name("Usage Threshold")

Mime
View raw message