Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -179,4 +179,18 @@ public static PooledByteBufAllocator createPooledByteBufAllocator(
allowCache ? PooledByteBufAllocator.defaultUseCacheForAllThreads() : false
);
}

/**
* ByteBuf allocator prefers to allocate direct ByteBuf iif both Spark allows to create direct
* ByteBuf and Netty enables directBufferPreferred.
*/
public static boolean preferDirectBufs(TransportConf conf) {
boolean allowDirectBufs;
if (conf.sharedByteBufAllocators()) {
allowDirectBufs = conf.preferDirectBufsForSharedByteBufAllocators();
} else {
allowDirectBufs = conf.preferDirectBufs();
}
return allowDirectBufs && PlatformDependent.directBufferPreferred();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import org.apache.spark.deploy.SparkHadoopUtil
import org.apache.spark.deploy.worker.WorkerWatcher
import org.apache.spark.internal.Logging
import org.apache.spark.internal.config._
import org.apache.spark.network.netty.SparkTransportConf
import org.apache.spark.network.util.NettyUtils
import org.apache.spark.resource.ResourceInformation
import org.apache.spark.resource.ResourceProfile
import org.apache.spark.resource.ResourceProfile._
Expand Down Expand Up @@ -85,7 +87,8 @@ private[spark] class CoarseGrainedExecutorBackend(

logInfo("Connecting to driver: " + driverUrl)
try {
if (PlatformDependent.directBufferPreferred() &&
val shuffleClientTransportConf = SparkTransportConf.fromSparkConf(env.conf, "shuffle")
if (NettyUtils.preferDirectBufs(shuffleClientTransportConf) &&
PlatformDependent.maxDirectMemory() < env.conf.get(MAX_REMOTE_BLOCK_SIZE_FETCH_TO_MEM)) {
throw new SparkException(s"Netty direct memory should at least be bigger than " +
s"'${MAX_REMOTE_BLOCK_SIZE_FETCH_TO_MEM.key}', but got " +
Expand Down