-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21527][CORE] Use buffer limit in order to use JAVA NIO Util's buffercache #18730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7cbadc5
[SPARK][CORE] Slice write by channel
caneMi fc91f96
Fix code style
caneGuy bab91db
Refine to avoid underflow
caneGuy 72aef67
Fix no ending loop
caneGuy 4789772
Remove useless unit test
caneGuy aeabe1d
Delete unused package
caneGuy ca77b51
Add benchmark testing with Utils.BenchMark
caneGuy e84a6d7
Refine code style
caneGuy d708142
Update as comment replace writeFully with slice logic
caneGuy 33a2796
Remove unused package
caneGuy ab384d4
No need call toInt
caneGuy b669351
Only need to use bytes.remaining()
caneGuy 717f886
Use config for NIO_BUFFER_LIMIT
caneGuy 9d3004d
Use BUFFER_WRITE_CHUNK_SIZE
caneGuy e48f44f
Update as commented
caneGuy fc184aa
Fix build error
caneGuy f1d67a3
Fix compile error and refine scala style
caneGuy 14ca824
Need to convert to int to fix compile error
caneGuy a02575e
Avoid per-loop type cast
caneGuy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ import java.nio.channels.WritableByteChannel | |
| import com.google.common.primitives.UnsignedBytes | ||
| import io.netty.buffer.{ByteBuf, Unpooled} | ||
|
|
||
| import org.apache.spark.SparkEnv | ||
| import org.apache.spark.internal.config | ||
| import org.apache.spark.network.util.ByteArrayWritableChannel | ||
| import org.apache.spark.storage.StorageUtils | ||
|
|
||
|
|
@@ -40,6 +42,11 @@ private[spark] class ChunkedByteBuffer(var chunks: Array[ByteBuffer]) { | |
| require(chunks != null, "chunks must not be null") | ||
| require(chunks.forall(_.position() == 0), "chunks' positions must be 0") | ||
|
|
||
| // Chunk size in bytes | ||
| private val bufferWriteChunkSize = | ||
| Option(SparkEnv.get).map(_.conf.get(config.BUFFER_WRITE_CHUNK_SIZE)) | ||
| .getOrElse(config.BUFFER_WRITE_CHUNK_SIZE.defaultValue.get) | ||
|
|
||
| private[this] var disposed: Boolean = false | ||
|
|
||
| /** | ||
|
|
@@ -56,7 +63,9 @@ private[spark] class ChunkedByteBuffer(var chunks: Array[ByteBuffer]) { | |
| */ | ||
| def writeFully(channel: WritableByteChannel): Unit = { | ||
| for (bytes <- getChunks()) { | ||
| while (bytes.remaining > 0) { | ||
| while (bytes.remaining() > 0) { | ||
| val ioSize = Math.min(bytes.remaining(), bufferWriteChunkSize) | ||
| bytes.limit(bytes.position + ioSize.toInt) | ||
|
||
| channel.write(bytes) | ||
| } | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a
checkValueto make sure the value is smaller thanInt.Max