You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2015/10/25 10:13:17 UTC
incubator-kylin git commit: KYLIN-1068 reuse array in
DoulbeDeltaSerializer to avoid OOM error
Repository: incubator-kylin
Updated Branches:
refs/heads/KYLIN-1068 a5b271452 -> ae9c4c086
KYLIN-1068 reuse array in DoulbeDeltaSerializer to avoid OOM error
Project: http://git-wip-us.apache.org/repos/asf/incubator-kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kylin/commit/ae9c4c08
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kylin/tree/ae9c4c08
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kylin/diff/ae9c4c08
Branch: refs/heads/KYLIN-1068
Commit: ae9c4c0860499cbb23c85c6c38b2be3eeb0b9b6b
Parents: a5b2714
Author: shaofengshi <sh...@apache.org>
Authored: Sun Oct 25 17:13:11 2015 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Sun Oct 25 17:13:11 2015 +0800
----------------------------------------------------------------------
.../common/topn/DoubleDeltaSerializer.java | 21 ++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kylin/blob/ae9c4c08/core-common/src/main/java/org/apache/kylin/common/topn/DoubleDeltaSerializer.java
----------------------------------------------------------------------
diff --git a/core-common/src/main/java/org/apache/kylin/common/topn/DoubleDeltaSerializer.java b/core-common/src/main/java/org/apache/kylin/common/topn/DoubleDeltaSerializer.java
index 2dfb5b0..4ce2e0c 100644
--- a/core-common/src/main/java/org/apache/kylin/common/topn/DoubleDeltaSerializer.java
+++ b/core-common/src/main/java/org/apache/kylin/common/topn/DoubleDeltaSerializer.java
@@ -41,6 +41,9 @@ public class DoubleDeltaSerializer {
final private int precision;
final private int multiplier;
+
+ transient ThreadLocal<long[]> deltasThreadLocal;
+
public DoubleDeltaSerializer() {
this(2);
}
@@ -53,6 +56,7 @@ public class DoubleDeltaSerializer {
this.precision = precision;
this.multiplier = (int) Math.pow(10, precision);
+ this.deltasThreadLocal = new ThreadLocal<long[]>();
}
public void serialize(double values[], ByteBuffer buf) {
@@ -108,19 +112,24 @@ public class DoubleDeltaSerializer {
private long[] calculateDeltas(double[] values) {
int len = values.length - 1;
len = Math.max(0, len);
- long[] reuseDeltas = new long[len];
-
+
+ long[] deltas = deltasThreadLocal.get();
+ if (deltas == null) {
+ deltas = new long[len];
+ deltasThreadLocal.set(deltas);
+ }
+
if (len == 0)
- return reuseDeltas;
+ return deltas;
long current = roundAndPromote(values[0]);
for (int i = 0; i < len; i++) {
long next = roundAndPromote(values[i + 1]);
- reuseDeltas[i] = next - current;
- assert reuseDeltas[i] >= 0;
+ deltas[i] = next - current;
+ assert deltas[i] >= 0;
current = next;
}
- return reuseDeltas;
+ return deltas;
}
private long roundAndPromote(double value) {