Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
18 changes: 8 additions & 10 deletions core/src/main/scala/org/apache/spark/rdd/CoalescedRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ private[spark] class CoalescedRDD[T: ClassTag](

private class DefaultPartitionCoalescer(val balanceSlack: Double = 0.10)
extends PartitionCoalescer {
def compare(o1: PartitionGroup, o2: PartitionGroup): Boolean = o1.numPartitions < o2.numPartitions
def compare(o1: Option[PartitionGroup], o2: Option[PartitionGroup]): Boolean =
if (o1 == None) false else if (o2 == None) true else compare(o1.get, o2.get)

val rnd = new scala.util.Random(7919) // keep this class deterministic

Expand Down Expand Up @@ -213,15 +210,17 @@ private class DefaultPartitionCoalescer(val balanceSlack: Double = 0.10)
}

/**
* Sorts and gets the least element of the list associated with key in groupHash
* Gets the least element of the list associated with key in groupHash
* The returned PartitionGroup is the least loaded of all groups that represent the machine "key"
*
* @param key string representing a partitioned group on preferred machine key
* @return Option of [[PartitionGroup]] that has least elements for key
*/
def getLeastGroupHash(key: String): Option[PartitionGroup] = {
groupHash.get(key).map(_.sortWith(compare).head)
}
def getLeastGroupHash(key: String): Option[PartitionGroup] =
groupHash
Comment thread
fitermay marked this conversation as resolved.
Outdated
.get(key)
.filter(_.nonEmpty)
.map(_.minBy(_.numPartitions))

def addPartToPGroup(part: Partition, pgroup: PartitionGroup): Boolean = {
if (!initialHash.contains(part)) {
Expand Down Expand Up @@ -297,9 +296,8 @@ private class DefaultPartitionCoalescer(val balanceSlack: Double = 0.10)
partitionLocs: PartitionLocations): PartitionGroup = {
val slack = (balanceSlack * prev.partitions.length).toInt
// least loaded pref locs
val pref = currPrefLocs(p, prev).map(getLeastGroupHash(_)).sortWith(compare)
val prefPart = if (pref == Nil) None else pref.head

val pref = currPrefLocs(p, prev).flatMap(getLeastGroupHash)
val prefPart = if (pref.isEmpty) None else Some(pref.minBy(_.numPartitions))
val r1 = rnd.nextInt(groupArr.size)
val r2 = rnd.nextInt(groupArr.size)
val minPowerOfTwo = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.spark.rdd
import scala.collection.immutable
Comment thread
fitermay marked this conversation as resolved.

import org.apache.spark.{DebugFilesystem, SparkConf, SparkContext}
import org.apache.spark.benchmark.{Benchmark, BenchmarkBase}

object CoalescedRDDBenchmark extends BenchmarkBase {
Comment thread
fitermay marked this conversation as resolved.

val seed = 0x1337
var conf = new SparkConf(false)
val sc = new SparkContext(
"local[4]",
"test",
conf.set("spark.hadoop.fs.file.impl", classOf[DebugFilesystem].getName))
Comment thread
fitermay marked this conversation as resolved.
Outdated

private def coalescedRDD(numIters: Int): Unit = {
val numBlocks = 100000
val benchmark = new Benchmark("Coalesced RDD", numBlocks, output = output)
for (numPartitions <- Seq(100, 500, 1000, 5000, 10000)) {
for (numHosts <- Seq(1, 5, 10, 20, 40, 80)) {

import collection.mutable
val hosts = mutable.ArrayBuffer[String]()
(1 to numHosts).foreach(hosts += "m" + _)
hosts.length
val rnd = scala.util.Random
rnd.setSeed(seed)
val blocks: immutable.Seq[(Int, Seq[String])] = (1 to numBlocks).map { i =>
(i, hosts(rnd.nextInt(hosts.size)) :: Nil)
}

benchmark.addCase(
s"Coalesce Num Partitions: $numPartitions Num Hosts: $numHosts",
numIters) { _ =>
performCoalesce(blocks, numPartitions)
}
}
}

benchmark.run()
}

private def performCoalesce(blocks: immutable.Seq[(Int, Seq[String])], numPartitions: Int) {
sc.makeRDD(blocks).coalesce(numPartitions).partitions
}

override def runBenchmarkSuite(mainArgs: Array[String]): Unit = {
val numIters = 3
runBenchmark("Coalesced RDD , large scale") {
coalescedRDD(numIters)
}
Comment thread
fitermay marked this conversation as resolved.
}
}