Skip to content

Commit eaf3e46

Browse files
committed
Ability to use heap buffer for large queries
1 parent b7b8efe commit eaf3e46

File tree

1 file changed

+23
-2
lines changed
  • pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/forward

1 file changed

+23
-2
lines changed

pinot-segment-local/src/main/java/org/apache/pinot/segment/local/segment/index/readers/forward/ChunkReaderContext.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import org.apache.pinot.segment.spi.index.reader.ForwardIndexReader;
2626
import org.apache.pinot.segment.spi.index.reader.ForwardIndexReaderContext;
2727
import org.apache.pinot.segment.spi.memory.CleanerUtil;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
2830

2931

3032
/**
@@ -39,22 +41,41 @@
3941
* </ul>
4042
*/
4143
public class ChunkReaderContext implements ForwardIndexReaderContext {
44+
private static final Logger LOGGER = LoggerFactory.getLogger(ChunkReaderContext.class);
45+
46+
private static final boolean USE_HEAP_FOR_LARGE_CHUNKS;
47+
private static final long MAX_DIRECT_BUFFER_CHUNK_SIZE;
48+
// default max direct buffer threshold size: 2MB
49+
private static final long DEFAULT_MAX_DIRECT_BUFFER_CHUNK_SIZE = 2 * 1024 * 1024L;
50+
4251
private final ByteBuffer _chunkBuffer;
4352

4453
private int _chunkId;
4554

4655
private List<ForwardIndexReader.ByteRange> _ranges;
4756

57+
static {
58+
USE_HEAP_FOR_LARGE_CHUNKS = Boolean.parseBoolean(System.getProperty("useHeapForLargeChunks", "false"));
59+
MAX_DIRECT_BUFFER_CHUNK_SIZE = Long.parseLong(System.getProperty("maxDirectBufferChunkSize",
60+
Long.toString(DEFAULT_MAX_DIRECT_BUFFER_CHUNK_SIZE)));
61+
LOGGER.info("useHeapForLargeChunks: {}, maxDirectBufferChunkSize: {}",
62+
USE_HEAP_FOR_LARGE_CHUNKS, MAX_DIRECT_BUFFER_CHUNK_SIZE);
63+
}
64+
4865
public ChunkReaderContext(int maxChunkSize) {
49-
_chunkBuffer = ByteBuffer.allocateDirect(maxChunkSize);
66+
if (!USE_HEAP_FOR_LARGE_CHUNKS || maxChunkSize < MAX_DIRECT_BUFFER_CHUNK_SIZE) {
67+
_chunkBuffer = ByteBuffer.allocateDirect(maxChunkSize);
68+
} else {
69+
_chunkBuffer = ByteBuffer.allocate(maxChunkSize);
70+
}
5071
_chunkId = -1;
5172
_ranges = new ArrayList<>();
5273
}
5374

5475
@Override
5576
public void close()
5677
throws IOException {
57-
if (CleanerUtil.UNMAP_SUPPORTED) {
78+
if (CleanerUtil.UNMAP_SUPPORTED && _chunkBuffer.isDirect()) {
5879
CleanerUtil.getCleaner().freeBuffer(_chunkBuffer);
5980
}
6081
}

0 commit comments

Comments
 (0)