clintropolis commented on code in PR #16698:
URL: https://github.com/apache/druid/pull/16698#discussion_r1668085976


##########
processing/src/main/java/org/apache/druid/segment/writeout/FileWriteOutBytes.java:
##########
@@ -33,22 +33,25 @@
 import java.nio.channels.FileChannel;
 import java.nio.channels.WritableByteChannel;
 
-final class FileWriteOutBytes extends WriteOutBytes
+public final class FileWriteOutBytes extends WriteOutBytes
 {
   private final File file;
   private final FileChannel ch;
   private long writeOutBytes;
 
-  /** Purposely big-endian, for {@link #writeInt(int)} implementation */
-  private final ByteBuffer buffer = ByteBuffer.allocate(4096); // 4K page 
sized buffer
+  /**
+   * Purposely big-endian, for {@link #writeInt(int)} implementation.
+   * Direct because there is a material difference in performance when writing 
direct buffers
+   */
+  private final ByteBuffer buffer = ByteBuffer.allocateDirect(32768); // 32K 
page sized buffer

Review Comment:
   this will leak direct memory, it needs to be grabbed from a pool or like use 
`ByteBufferUtils.free` 
https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/java/util/common/ByteBufferUtils.java#L199
 when we are done with it.
   
   We should almost never be calling `ByteBuffer.allocateDirect` in code unless 
tracking it



##########
processing/src/main/java/org/apache/druid/segment/writeout/TmpFileSegmentWriteOutMedium.java:
##########
@@ -43,21 +69,41 @@ public final class TmpFileSegmentWriteOutMedium implements 
SegmentWriteOutMedium
   @Override
   public WriteOutBytes makeWriteOutBytes() throws IOException
   {
-    File file = File.createTempFile("filePeon", null, dir);
-    FileChannel ch = FileChannel.open(
-        file.toPath(),
-        StandardOpenOption.READ,
-        StandardOpenOption.WRITE
+    return new LazilyAllocatingHeapWriteOutBytes(

Review Comment:
   why not implement a new `SegmentWriteOutMedium` instead of changing the 
behavior of an existing one?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to