flink版本: flink-1.11.2
代码位置: org.apache.flink.runtime.util.EnvironmentInformation
调用位置: taskmanager启动类:
org.apache.flink.runtime.taskexecutor.TaskManagerRunner文章来源:https://www.toymoban.com/news/detail-683383.html
long maxOpenFileHandles = EnvironmentInformation.getOpenFileHandlesLimit();
注意,该方法主要调用了com.sun.management.UnixOperatingSystemMXBean接口下的getMaxFileDescriptorCount方法,所以一定要在Sun/Oracle的JDK下才能使用。另外只能在基于Unix内核的操作系统中生效,其他系统下默认返回-1.文章来源地址https://www.toymoban.com/news/detail-683383.html
/**
* 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() {
if(OperatingSystem.isWindows()) { // getMaxFileDescriptorCount method is not available on Windows
return -1L;
}
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;
}
}
到了这里,关于flink源码分析-获取最大可以打开的文件句柄的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!