[FLINK-2327] [runtime] Log the limit of open file handles at TaskManager startup


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/706c391b
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/706c391b
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/706c391b

Branch: refs/heads/master
Commit: 706c391b11ac6fc8c1487cbe43b20b5510c7a459
Parents: 535475c
Author: Stephan Ewen <[email protected]>
Authored: Wed Jul 8 15:47:45 2015 +0200
Committer: Stephan Ewen <[email protected]>
Committed: Wed Jul 8 20:28:40 2015 +0200

----------------------------------------------------------------------
 .../runtime/util/EnvironmentInformation.java    | 29 ++++++++++++++++++++
 .../flink/runtime/taskmanager/TaskManager.scala |  7 +++++
 .../util/EnvironmentInformationTest.java        |  1 +
 3 files changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/706c391b/flink-runtime/src/main/java/org/apache/flink/runtime/util/EnvironmentInformation.java
----------------------------------------------------------------------
diff --git 
a/flink-runtime/src/main/java/org/apache/flink/runtime/util/EnvironmentInformation.java
 
b/flink-runtime/src/main/java/org/apache/flink/runtime/util/EnvironmentInformation.java
index 4efdf11..630e227 100644
--- 
a/flink-runtime/src/main/java/org/apache/flink/runtime/util/EnvironmentInformation.java
+++ 
b/flink-runtime/src/main/java/org/apache/flink/runtime/util/EnvironmentInformation.java
@@ -21,6 +21,7 @@ package org.apache.flink.runtime.util;
 import java.io.InputStream;
 import java.lang.management.ManagementFactory;
 import java.lang.management.RuntimeMXBean;
+import java.lang.reflect.Method;
 import java.util.List;
 import java.util.Properties;
 
@@ -202,6 +203,34 @@ public class EnvironmentInformation {
        }
 
        /**
+        * Tries to retrieve the maximum number of open file handles. This 
method will only work on
+        * UNIX-based operating systems with Sun/Oracle Java versions.
+        * 
+        * <p>If the number of max open file handles cannot be determined, this 
method returns {@code -1}.</p>
+        * 
+        * @return The limit of open file handles, or {@code -1}, if the limit 
could not be determined.
+        */
+       public static long getOpenFileHandlesLimit() {
+               Class<?> sunBeanClass;
+               try {
+                       sunBeanClass = 
Class.forName("com.sun.management.UnixOperatingSystemMXBean");
+               }
+               catch (ClassNotFoundException e) {
+                       return -1L;
+               }
+               
+               try {
+                       Method fhLimitMethod = 
sunBeanClass.getMethod("getMaxFileDescriptorCount");
+                       Object result = 
fhLimitMethod.invoke(ManagementFactory.getOperatingSystemMXBean());
+                       return (Long) result;
+               }
+               catch (Throwable t) {
+                       LOG.warn("Unexpected error when accessing file handle 
limit", t);
+                       return -1L;
+               }
+       }
+       
+       /**
         * Logs a information about the environment, like code revision, 
current user, java version,
         * and JVM parameters.
         *

http://git-wip-us.apache.org/repos/asf/flink/blob/706c391b/flink-runtime/src/main/scala/org/apache/flink/runtime/taskmanager/TaskManager.scala
----------------------------------------------------------------------
diff --git 
a/flink-runtime/src/main/scala/org/apache/flink/runtime/taskmanager/TaskManager.scala
 
b/flink-runtime/src/main/scala/org/apache/flink/runtime/taskmanager/TaskManager.scala
index 4f95c1c..9bdf1a8 100644
--- 
a/flink-runtime/src/main/scala/org/apache/flink/runtime/taskmanager/TaskManager.scala
+++ 
b/flink-runtime/src/main/scala/org/apache/flink/runtime/taskmanager/TaskManager.scala
@@ -1032,6 +1032,13 @@ object TaskManager {
     EnvironmentInformation.logEnvironmentInfo(LOG.logger, "TaskManager", args)
     EnvironmentInformation.checkJavaVersion()
 
+    val maxOpenFileHandles = EnvironmentInformation.getOpenFileHandlesLimit()
+    if (maxOpenFileHandles == -1) {
+      LOG.info(s"Maximum number of open file descriptors is 
$maxOpenFileHandles")
+    } else {
+      LOG.info("Cannot determine the maximum number of open file descriptors")
+    }
+    
     // try to parse the command line arguments
     val (configuration: Configuration,
          mode: StreamingMode) = try {

http://git-wip-us.apache.org/repos/asf/flink/blob/706c391b/flink-runtime/src/test/java/org/apache/flink/runtime/util/EnvironmentInformationTest.java
----------------------------------------------------------------------
diff --git 
a/flink-runtime/src/test/java/org/apache/flink/runtime/util/EnvironmentInformationTest.java
 
b/flink-runtime/src/test/java/org/apache/flink/runtime/util/EnvironmentInformationTest.java
index 764cb57..771c57c 100644
--- 
a/flink-runtime/src/test/java/org/apache/flink/runtime/util/EnvironmentInformationTest.java
+++ 
b/flink-runtime/src/test/java/org/apache/flink/runtime/util/EnvironmentInformationTest.java
@@ -56,6 +56,7 @@ public class EnvironmentInformationTest {
                        
assertNotNull(EnvironmentInformation.getRevisionInformation());
                        assertNotNull(EnvironmentInformation.getVersion());
                        assertNotNull(EnvironmentInformation.getUserRunning());
+                       
assertTrue(EnvironmentInformation.getOpenFileHandlesLimit() >= -1);
                }
                catch (Exception e) {
                        e.printStackTrace();

Reply via email to