浏览代码

HDFS-8009. Signal congestion on the DataNode. Contributed by Haohui Mai.

Haohui Mai 10 年之前
父节点
当前提交
a5bcfe0d33

+ 2 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

@@ -56,6 +56,8 @@ Release 2.8.0 - UNRELEASED
     HDFS-7671. hdfs user guide should point to the common rack awareness doc.
     (Kai Sasaki via aajisaka)
 
+    HDFS-8009. Signal congestion on the DataNode. (wheat9)
+
   OPTIMIZATIONS
 
   BUG FIXES

+ 10 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java

@@ -357,6 +357,9 @@ public class DataNode extends ReconfigurableBase
   private String dnUserName = null;
 
   private SpanReceiverHost spanReceiverHost;
+  private static final int NUM_CORES = Runtime.getRuntime()
+      .availableProcessors();
+  private static final double CONGESTION_RATIO = 1.5;
 
   /**
    * Creates a dummy DataNode for testing purpose.
@@ -487,8 +490,13 @@ public class DataNode extends ReconfigurableBase
    * </ul>
    */
   public PipelineAck.ECN getECN() {
-    return pipelineSupportECN ? PipelineAck.ECN.SUPPORTED : PipelineAck.ECN
-      .DISABLED;
+    if (!pipelineSupportECN) {
+      return PipelineAck.ECN.DISABLED;
+    }
+    double load = ManagementFactory.getOperatingSystemMXBean()
+        .getSystemLoadAverage();
+    return load > NUM_CORES * CONGESTION_RATIO ? PipelineAck.ECN.CONGESTED :
+        PipelineAck.ECN.SUPPORTED;
   }
 
   /**