Skip to content

Commit 93f92c0

Browse files
jerryshaozsxwing
authored andcommitted
[SPARK-21475][CORE][2ND ATTEMPT] Change to use NIO's Files API for external shuffle service
## What changes were proposed in this pull request? This PR is the second attempt of #18684 , NIO's Files API doesn't override `skip` method for `InputStream`, so it will bring in performance issue (mentioned in #20119). But using `FileInputStream`/`FileOutputStream` will also bring in memory issue (https://dzone.com/articles/fileinputstream-fileoutputstream-considered-harmful), which is severe for long running external shuffle service. So here in this proposal, only fixing the external shuffle service related code. ## How was this patch tested? Existing tests. Author: jerryshao <[email protected]> Closes #20144 from jerryshao/SPARK-21475-v2.
1 parent 6f68316 commit 93f92c0

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

common/network-common/src/main/java/org/apache/spark/network/buffer/FileSegmentManagedBuffer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.RandomAccessFile;
2525
import java.nio.ByteBuffer;
2626
import java.nio.channels.FileChannel;
27+
import java.nio.file.StandardOpenOption;
2728

2829
import com.google.common.base.Objects;
2930
import com.google.common.io.ByteStreams;
@@ -132,7 +133,7 @@ public Object convertToNetty() throws IOException {
132133
if (conf.lazyFileDescriptor()) {
133134
return new DefaultFileRegion(file, offset, length);
134135
} else {
135-
FileChannel fileChannel = new FileInputStream(file).getChannel();
136+
FileChannel fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.READ);
136137
return new DefaultFileRegion(fileChannel, offset, length);
137138
}
138139
}

common/network-shuffle/src/main/java/org/apache/spark/network/shuffle/ShuffleIndexInformation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
import java.io.DataInputStream;
2121
import java.io.File;
22-
import java.io.FileInputStream;
2322
import java.io.IOException;
2423
import java.nio.ByteBuffer;
2524
import java.nio.LongBuffer;
25+
import java.nio.file.Files;
2626

2727
/**
2828
* Keeps the index information for a particular map output
@@ -39,7 +39,7 @@ public ShuffleIndexInformation(File indexFile) throws IOException {
3939
offsets = buffer.asLongBuffer();
4040
DataInputStream dis = null;
4141
try {
42-
dis = new DataInputStream(new FileInputStream(indexFile));
42+
dis = new DataInputStream(Files.newInputStream(indexFile.toPath()));
4343
dis.readFully(buffer.array());
4444
} finally {
4545
if (dis != null) {

0 commit comments

Comments
 (0)