From 1d0796498762d7688038972c9793be48d3730a8f Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Tue, 6 Sep 2016 15:39:36 -0700 Subject: [PATCH] LimitedTemporaryStorage: Fix perf bug. (#3432) FilterOutputStream has an inefficient implementation of write(byte[], int, int). So let's extend OutputStream directly and use efficient implementations of all methods. --- .../LimitedTemporaryStorage.java | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/processing/src/main/java/io/druid/query/groupby/epinephelinae/LimitedTemporaryStorage.java b/processing/src/main/java/io/druid/query/groupby/epinephelinae/LimitedTemporaryStorage.java index ecf5ab5ad8e..748b0328cbf 100644 --- a/processing/src/main/java/io/druid/query/groupby/epinephelinae/LimitedTemporaryStorage.java +++ b/processing/src/main/java/io/druid/query/groupby/epinephelinae/LimitedTemporaryStorage.java @@ -110,6 +110,11 @@ public class LimitedTemporaryStorage implements Closeable } } + public long maxSize() + { + return maxBytesUsed; + } + @Override public void close() { @@ -128,35 +133,48 @@ public class LimitedTemporaryStorage implements Closeable } } - public class LimitedOutputStream extends FilterOutputStream + public class LimitedOutputStream extends OutputStream { private final File file; + private final OutputStream out; private LimitedOutputStream(File file, OutputStream out) { - super(out); this.file = file; + this.out = out; } @Override public void write(int b) throws IOException { grab(1); - super.write(b); + out.write(b); } @Override public void write(byte[] b) throws IOException { grab(b.length); - super.write(b); + out.write(b); } @Override public void write(byte[] b, int off, int len) throws IOException { grab(len); - super.write(b, off, len); + out.write(b, off, len); + } + + @Override + public void flush() throws IOException + { + out.flush(); + } + + @Override + public void close() throws IOException + { + out.close(); } public File getFile()