You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by xu...@apache.org on 2015/11/12 04:59:53 UTC

[29/55] [abbrv] hive git commit: HIVE-12310: Update memory estimation login in TopNHash (Hari Subramaniyan, reviewed by Thejas Nair)

HIVE-12310: Update memory estimation login in TopNHash (Hari Subramaniyan, reviewed by Thejas Nair)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/678b77b5
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/678b77b5
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/678b77b5

Branch: refs/heads/spark
Commit: 678b77b5be2e97581a49fdb47614274f1ea8a7a5
Parents: 6ba735f
Author: Hari Subramaniyan <ha...@apache.org>
Authored: Fri Nov 6 10:39:25 2015 -0800
Committer: Hari Subramaniyan <ha...@apache.org>
Committed: Fri Nov 6 10:39:25 2015 -0800

----------------------------------------------------------------------
 ql/src/java/org/apache/hadoop/hive/ql/exec/TopNHash.java | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/678b77b5/ql/src/java/org/apache/hadoop/hive/ql/exec/TopNHash.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/TopNHash.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/TopNHash.java
index 46b3510..e400368 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/TopNHash.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/TopNHash.java
@@ -103,8 +103,13 @@ public class TopNHash {
       return; // topN == 0 will cause a short-circuit, don't need any initialization
     }
 
+    // Used Memory = totalMemory() - freeMemory();
+    // Total Free Memory = maxMemory() - Used Memory;
+    long totalFreeMemory = Runtime.getRuntime().maxMemory() -
+      Runtime.getRuntime().totalMemory() + Runtime.getRuntime().freeMemory();
+
     // limit * 64 : compensation of arrays for key/value/hashcodes
-    this.threshold = (long) (memUsage * Runtime.getRuntime().freeMemory()) - topN * 64L;
+    this.threshold = (long) (memUsage * totalFreeMemory) - topN * 64L;
     if (threshold < 0) {
       return;
     }