Skip to content

Commit

Permalink
[SPARK-27464][CORE] Added Constant instead of referring string litera…
Browse files Browse the repository at this point in the history
…l used from many places

## What changes were proposed in this pull request?

Added Constant instead of referring the same String literal "spark.buffer.pageSize" from many places
## How was this patch tested?
Run the corresponding Unit Test Cases manually.

Closes apache#24368 from shivusondur/Constant.

Authored-by: shivusondur <[email protected]>
Signed-off-by: Sean Owen <[email protected]>
  • Loading branch information
shivusondur authored and srowen committed Apr 16, 2019
1 parent 257d01a commit 88d9de2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1303,4 +1303,10 @@ package object config {
.doc("Staging directory used while submitting applications.")
.stringConf
.createOptional

private[spark] val BUFFER_PAGESIZE = ConfigBuilder("spark.buffer.pageSize")
.doc("The amount of memory used per page in bytes")
.bytesConf(ByteUnit.BYTE)
.createOptional

}
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private[spark] abstract class MemoryManager(
}
val size = ByteArrayMethods.nextPowerOf2(maxTungstenMemory / cores / safetyFactor)
val default = math.min(maxPageSize, math.max(minPageSize, size))
conf.getSizeAsBytes("spark.buffer.pageSize", default)
conf.get(BUFFER_PAGESIZE).getOrElse(default)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void setUp() throws IOException {
partitionSizesInMergedFile = null;
spillFilesCreated.clear();
conf = new SparkConf()
.set("spark.buffer.pageSize", "1m")
.set(package$.MODULE$.BUFFER_PAGESIZE().key(), "1m")
.set(package$.MODULE$.MEMORY_OFFHEAP_ENABLED(), false);
taskMetrics = new TaskMetrics();
memoryManager = new TestMemoryManager(conf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public int compare(

protected boolean shouldUseRadixSort() { return false; }

private final long pageSizeBytes = conf.getSizeAsBytes("spark.buffer.pageSize", "4m");
private final long pageSizeBytes = conf.getSizeAsBytes(
package$.MODULE$.BUFFER_PAGESIZE().key(), "4m");

private final int spillThreshold =
(int) conf.get(package$.MODULE$.SHUFFLE_SPILL_NUM_ELEMENTS_FORCE_SPILL_THRESHOLD());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.esotericsoftware.kryo.{Kryo, KryoSerializable}
import com.esotericsoftware.kryo.io.{Input, Output}

import org.apache.spark.{SparkConf, SparkEnv, SparkException}
import org.apache.spark.internal.config.MEMORY_OFFHEAP_ENABLED
import org.apache.spark.internal.config.{BUFFER_PAGESIZE, MEMORY_OFFHEAP_ENABLED}
import org.apache.spark.memory._
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions._
Expand Down Expand Up @@ -235,7 +235,7 @@ private[joins] class UnsafeHashedRelation(
0)

val pageSizeBytes = Option(SparkEnv.get).map(_.memoryManager.pageSizeBytes)
.getOrElse(new SparkConf().getSizeAsBytes("spark.buffer.pageSize", "16m"))
.getOrElse(new SparkConf().get(BUFFER_PAGESIZE).getOrElse(16L * 1024 * 1024))

// TODO(josh): We won't need this dummy memory manager after future refactorings; revisit
// during code review
Expand Down Expand Up @@ -285,8 +285,7 @@ private[joins] object UnsafeHashedRelation {
taskMemoryManager: TaskMemoryManager): HashedRelation = {

val pageSizeBytes = Option(SparkEnv.get).map(_.memoryManager.pageSizeBytes)
.getOrElse(new SparkConf().getSizeAsBytes("spark.buffer.pageSize", "16m"))

.getOrElse(new SparkConf().get(BUFFER_PAGESIZE).getOrElse(16L * 1024 * 1024))
val binaryMap = new BytesToBytesMap(
taskMemoryManager,
// Only 70% of the slots can be used before growing, more capacity help to reduce collision
Expand Down

0 comments on commit 88d9de2

Please sign in to comment.