Skip to content
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ package object config {
.intConf
.createWithDefault(3)

private[spark] val BUFFER_WRITE_CHUNK_SIZE =
ConfigBuilder("spark.buffer.write.chunkSize")
.internal()
.doc("The block size limit when use ChunkedByteBuffer to writeFully bytes.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chunk size during writing out the bytes of ChunkedByteBuffer

.bytesConf(ByteUnit.BYTE)
.createWithDefault(64 * 1024 * 1024)

private[spark] val REDUCER_MAX_REQ_SIZE_SHUFFLE_TO_MEM =
ConfigBuilder("spark.reducer.maxReqSizeShuffleToMem")
.internal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import java.nio.channels.WritableByteChannel
import com.google.common.primitives.UnsignedBytes
import io.netty.buffer.{ByteBuf, Unpooled}

import org.apache.spark.internal.config
import org.apache.spark.network.util.ByteArrayWritableChannel
import org.apache.spark.storage.StorageUtils

Expand All @@ -40,6 +41,9 @@ 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 NIO_BUFFER_LIMIT = SparkEnv.get.conf.get(config.BUFFER_WRITE_CHUNK_SIZE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SparkEnv.get may be null in test cases, how about Option(SparkEnv.get).map(_.conf.get(BUFFER_WRITE_CHUNK_SIZE)).getOrElse(BUFFER_WRITE_CHUNK_SIZE.defaultValue.get)

Copy link
Contributor

@cloud-fan cloud-fan Aug 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this is not a constant any more, we should use lower-cased variable name, how about val bufferWriteChunkSize


private[this] var disposed: Boolean = false

/**
Expand All @@ -56,7 +60,10 @@ private[spark] class ChunkedByteBuffer(var chunks: Array[ByteBuffer]) {
*/
def writeFully(channel: WritableByteChannel): Unit = {
for (bytes <- getChunks()) {
while (bytes.remaining > 0) {
val capacity = bytes.limit()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is not used.

while (bytes.remaining() > 0) {
val ioSize = Math.min(bytes.remaining(), NIO_BUFFER_LIMIT)
bytes.limit(bytes.position + ioSize)
channel.write(bytes)
}
}
Expand Down