Use file channel in smoosher to minimize copy overheads#46
Use file channel in smoosher to minimize copy overheads#46leventov merged 6 commits intometamx:masterfrom
Conversation
9a12346 to
658822b
Compare
| File[] files = baseDir.listFiles(); | ||
| Assert.assertEquals(1, files.length); | ||
| Assert.assertEquals(0, files[0].length()); | ||
| Assert.assertEquals(4, files[0].length()); |
There was a problem hiding this comment.
it was buffered stream before but is not, making that difference. I've implemented buffered channel and it's restored as before.
b33d1c7 to
3470a80
Compare
| open = false; | ||
| out.close(); | ||
| if (buffer.position() != 0) { | ||
| flush(); |
There was a problem hiding this comment.
if flush throws IOException, does close() still need called?
3470a80 to
316001c
Compare
| public int write(InputStream in) throws IOException | ||
| { | ||
| return addToOffset(Ints.checkedCast(ByteStreams.copy(in, out))); | ||
| return addToOffset(ByteStreams.copy(Channels.newChannel(in), channel)); |
There was a problem hiding this comment.
Double buffering here. Channels.newChannel() returns a buffered channel, and then ByteStreams.copy() uses a buffer internally. Made google/guava#2559 about this but it's faster and easier to fix internally in the meantime
There was a problem hiding this comment.
Yes, I've neglected this because this is not used in Druid. But seemed good this to be fixed.
There was a problem hiding this comment.
Agree, could be a separate PR. Also found this idiom (ByteStream.copy(Channels.newChannel(), ...) is used in Druid in several places, so it's more a Druid's issue than java-util's
|
@navis do you have time to address the comments? I can do this myself and make a different PR based on your PR, but if it is merged with squash your authorship will be lost. |
5b0684e to
f11aaf2
Compare
|
@navis could you please make two things?
|
|
And after those changes |
|
@navis do you have capacity for doing this? |
|
@leventov Addressed comments |
|
@navis Thanks! |
Current
write(ByteBuffer buffer)implementation of smoother is something like this,And agagin,
but because
outis a BufferedOuputStream, this call always makes wrapper which copies ByteBuffer handed over to byte[], negating good intention of using it. I think it would be better to use FileChannel directly.