hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nkey...@apache.org
Subject svn commit: r1464918 - in /hbase/trunk/hbase-common/src: main/java/org/apache/hadoop/hbase/util/JVM.java test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java test/java/org/apache/hadoop/hbase/ResourceCheckerJUnitListener.java
Date Fri, 05 Apr 2013 10:42:35 GMT
Author: nkeywal
Date: Fri Apr  5 10:42:35 2013
New Revision: 1464918

URL: http://svn.apache.org/r1464918
Log:
HBASE-8267 Add some resources checker for tests

Modified:
    hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java
    hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java
    hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/ResourceCheckerJUnitListener.java

Modified: hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java?rev=1464918&r1=1464917&r2=1464918&view=diff
==============================================================================
--- hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java (original)
+++ hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java Fri Apr 
5 10:42:35 2013
@@ -100,14 +100,14 @@ public class JVM 
     try {
       classRef = Class.forName("com.sun.management.UnixOperatingSystemMXBean");
       if (classRef.isInstance(osMbean)) {
-        mBeanMethod = classRef.getDeclaredMethod(mBeanMethodName,
-          new Class[0]);
+        mBeanMethod = classRef.getMethod(mBeanMethodName, new Class[0]);
         unixos = classRef.cast(osMbean);
         return (Long)mBeanMethod.invoke(unixos);
       }
     }
     catch(Exception e) {
-      LOG.warn("Not able to load class or method for com.sun.managment.UnixOperatingSystemMXBean.",
e);
+      LOG.warn("Not able to load class or method for" +
+          " com.sun.management.UnixOperatingSystemMXBean.", e);
     }
     return null;
   }
@@ -165,6 +165,58 @@ public class JVM 
   }
 
   /**
+   * @see java.lang.management.OperatingSystemMXBean#getSystemLoadAverage
+   */
+  public double getSystemLoadAverage() {
+    return osMbean.getSystemLoadAverage();
+  }
+
+  /**
+   * @return the physical free memory (not the JVM one, as it's not very useful as it depends
on
+   *  the GC), but the one from the OS as it allows a little bit more to guess if the machine
is
+   *  overloaded or not).
+   */
+  public long getFreeMemory() {
+    if (ibmvendor){
+      return 0;
+    }
+
+    Long r =  runUnixMXBeanMethod("getFreePhysicalMemorySize");
+    return (r != null ? r : -1);
+  }
+
+
+  /**
+   * Workaround to get the current number of process running. Approach is the one described
here:
+   * http://stackoverflow.com/questions/54686/how-to-get-a-list-of-current-open-windows-process-with-java
+   */
+  public int getNumberOfRunningProcess(){
+    if (!isUnix()){
+      return 0;
+    }
+
+    BufferedReader input = null;
+    try {
+      int count = 0;
+      Process p = Runtime.getRuntime().exec("ps -e");
+      input = new BufferedReader(new InputStreamReader(p.getInputStream()));
+      while (input.readLine() != null) {
+        count++;
+      }
+      return count - 1; //  -1 because there is a headline
+    } catch (IOException e) {
+      return -1;
+    }  finally {
+      if (input != null){
+        try {
+          input.close();
+        } catch (IOException ignored) {
+        }
+      }
+    }
+  }
+
+  /**
    * Get the number of the maximum file descriptors the system can use.
    * If Oracle java, it will use the com.sun.management interfaces.
    * Otherwise, this methods implements it (linux only).  

Modified: hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java?rev=1464918&r1=1464917&r2=1464918&view=diff
==============================================================================
--- hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java
(original)
+++ hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseCommonTestingUtility.java
Fri Apr  5 10:42:35 2013
@@ -142,7 +142,7 @@ public class HBaseCommonTestingUtility {
    * @throws IOException
    */
   boolean deleteDir(final File dir) throws IOException {
-    if (dir != null && !dir.exists()) {
+    if (dir == null || !dir.exists()) {
       return true;
     }
     try {
@@ -153,4 +153,4 @@ public class HBaseCommonTestingUtility {
       return false;
     }
   }
-};
+}

Modified: hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/ResourceCheckerJUnitListener.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/ResourceCheckerJUnitListener.java?rev=1464918&r1=1464917&r2=1464918&view=diff
==============================================================================
--- hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/ResourceCheckerJUnitListener.java
(original)
+++ hbase/trunk/hbase-common/src/test/java/org/apache/hadoop/hbase/ResourceCheckerJUnitListener.java
Fri Apr  5 10:42:35 2013
@@ -20,8 +20,7 @@
 package org.apache.hadoop.hbase;
 
 
-import java.lang.management.ManagementFactory;
-import java.lang.management.OperatingSystemMXBean;
+
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
@@ -89,7 +88,7 @@ public class ResourceCheckerJUnitListene
   static class OpenFileDescriptorResourceAnalyzer extends ResourceChecker.ResourceAnalyzer
{
     @Override
     public int getVal(Phase phase) {
-      if (JVM.isUnix() == false) return 0;
+      if (!JVM.isUnix()) return 0;
       JVM jvm = new JVM();
       return (int)jvm.getOpenFileDescriptorCount();
     }
@@ -103,12 +102,36 @@ public class ResourceCheckerJUnitListene
   static class MaxFileDescriptorResourceAnalyzer extends ResourceChecker.ResourceAnalyzer
{
     @Override
     public int getVal(Phase phase) {
-      if (JVM.isUnix() == false) return 0;
+      if (!JVM.isUnix()) return 0;
       JVM jvm = new JVM();
       return (int)jvm.getMaxFileDescriptorCount();
      } 
    }
 
+  static class SystemLoadAverageResourceAnalyzer extends ResourceChecker.ResourceAnalyzer
{
+    @Override
+    public int getVal(Phase phase) {
+      if (!JVM.isUnix()) return 0;
+      return (int)(new JVM().getSystemLoadAverage()*100);
+    }
+  }
+
+  static class ProcessCountResourceAnalyzer extends ResourceChecker.ResourceAnalyzer {
+    @Override
+    public int getVal(Phase phase) {
+      if (!JVM.isUnix()) return 0;
+      return new JVM().getNumberOfRunningProcess();
+    }
+  }
+
+  static class AvailableMemoryMBResourceAnalyzer extends ResourceChecker.ResourceAnalyzer
{
+    @Override
+    public int getVal(Phase phase) {
+      if (!JVM.isUnix()) return 0;
+      return (int) (new JVM().getFreeMemory() / (1024L * 1024L));
+    }
+  }
+
 
   /**
    * To be implemented by sub classes if they want to add specific ResourceAnalyzer.
@@ -122,6 +145,9 @@ public class ResourceCheckerJUnitListene
     rc.addResourceAnalyzer(new ThreadResourceAnalyzer());
     rc.addResourceAnalyzer(new OpenFileDescriptorResourceAnalyzer());
     rc.addResourceAnalyzer(new MaxFileDescriptorResourceAnalyzer());
+    rc.addResourceAnalyzer(new SystemLoadAverageResourceAnalyzer());
+    rc.addResourceAnalyzer(new ProcessCountResourceAnalyzer());
+    rc.addResourceAnalyzer(new AvailableMemoryMBResourceAnalyzer());
 
     addResourceAnalyzer(rc);
 



Mime
View raw message