This repository was archived by the owner on Dec 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 771
Add repartition workload #608
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3c6007c
Add repartition workload
14334de
Docs
3b6a0fb
Not using RDD[Tuple2] so as to leverage unsafe shuffle writer
bf801cd
Add a parameter to switch on/off cache
708e8e6
Save RDDs in reduce stage
296e5ed
Change default
b5477ba
Write result or not configurable
fcf13d4
Travis?
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
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 |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/bin/bash | ||
| # 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. | ||
|
|
||
| current_dir=`dirname "$0"` | ||
| current_dir=`cd "$current_dir"; pwd` | ||
| root_dir=${current_dir}/../../../../.. | ||
| workload_config=${root_dir}/conf/workloads/micro/repartition.conf | ||
| . "${root_dir}/bin/functions/load_bench_config.sh" | ||
|
|
||
| enter_bench HadoopPrepareRepartition ${workload_config} ${current_dir} | ||
| show_bannar start | ||
|
|
||
| rmr_hdfs $INPUT_HDFS || true | ||
| START_TIME=`timestamp` | ||
| run_hadoop_job ${HADOOP_EXAMPLES_JAR} teragen \ | ||
| -D mapreduce.job.maps=${NUM_MAPS} \ | ||
| -D mapreduce.job.reduces=${NUM_REDS} \ | ||
| ${DATASIZE} ${INPUT_HDFS} | ||
| END_TIME=`timestamp` | ||
|
|
||
| show_bannar finish | ||
| leave_bench |
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 |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/bin/bash | ||
| # 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. | ||
|
|
||
| current_dir=`dirname "$0"` | ||
| current_dir=`cd "$current_dir"; pwd` | ||
| root_dir=${current_dir}/../../../../.. | ||
| workload_config=${root_dir}/conf/workloads/micro/repartition.conf | ||
| . "${root_dir}/bin/functions/load_bench_config.sh" | ||
|
|
||
| enter_bench ScalaRepartition ${workload_config} ${current_dir} | ||
| show_bannar start | ||
|
|
||
| rmr_hdfs $OUTPUT_HDFS || true | ||
|
|
||
| SIZE=`dir_size $INPUT_HDFS` | ||
| START_TIME=`timestamp` | ||
| run_spark_job com.intel.hibench.sparkbench.micro.ScalaRepartition $INPUT_HDFS $OUTPUT_HDFS $CACHE_IN_MEMORY $DISABLE_OUTPUT | ||
| END_TIME=`timestamp` | ||
|
|
||
| gen_report ${START_TIME} ${END_TIME} ${SIZE} | ||
| show_bannar finish | ||
| leave_bench | ||
|
|
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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ micro.sleep | |
| micro.sort | ||
| micro.terasort | ||
| micro.wordcount | ||
| micro.repartition | ||
| micro.dfsioe | ||
|
|
||
| sql.aggregation | ||
|
|
||
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 |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #datagen | ||
| hibench.repartition.tiny.datasize 3200 | ||
| hibench.repartition.small.datasize 3200000 | ||
| hibench.repartition.large.datasize 32000000 | ||
| hibench.repartition.huge.datasize 320000000 | ||
| hibench.repartition.gigantic.datasize 3200000000 | ||
| hibench.repartition.bigdata.datasize 6000000000 | ||
|
|
||
| hibench.workload.datasize ${hibench.repartition.${hibench.scale.profile}.datasize} | ||
|
|
||
| # export for shell script | ||
| hibench.workload.input ${hibench.hdfs.data.dir}/Repartition/Input | ||
| hibench.workload.output ${hibench.hdfs.data.dir}/Repartition/Output | ||
|
|
||
| hibench.repartition.cacheinmemory false | ||
| hibench.repartition.disableoutput false |
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
100 changes: 100 additions & 0 deletions
100
sparkbench/micro/src/main/scala/com/intel/sparkbench/micro/ScalaRepartition.scala
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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * 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 com.intel.hibench.sparkbench.micro | ||
|
|
||
| import java.util.Random | ||
|
|
||
| import com.intel.hibench.sparkbench.common.IOCommon | ||
| import org.apache.hadoop.examples.terasort.{TeraInputFormat, TeraOutputFormat} | ||
| import org.apache.hadoop.io.Text | ||
| import org.apache.spark._ | ||
| import org.apache.spark.rdd.{RDD, ShuffledRDD} | ||
| import org.apache.spark.storage.StorageLevel | ||
|
|
||
| import scala.util.hashing | ||
|
|
||
| object ScalaRepartition { | ||
|
|
||
| def main(args: Array[String]) { | ||
| if (args.length != 4) { | ||
| System.err.println( | ||
| s"Usage: $ScalaRepartition <INPUT_HDFS> <OUTPUT_HDFS> <CACHE_IN_MEMORY> <DISABLE_OUTPUT>" | ||
| ) | ||
| System.exit(1) | ||
| } | ||
| val cache = toBoolean(args(2), ("CACHE_IN_MEMORY")) | ||
| val disableOutput = toBoolean(args(3), ("DISABLE_OUTPUT")) | ||
|
|
||
| val sparkConf = new SparkConf().setAppName("ScalaRepartition") | ||
| val sc = new SparkContext(sparkConf) | ||
|
|
||
| val data = sc.newAPIHadoopFile[Text, Text, TeraInputFormat](args(0)).map { | ||
| case (k,v) => k.copyBytes ++ v.copyBytes | ||
| } | ||
|
|
||
| if (cache) { | ||
| data.persist(StorageLevel.MEMORY_ONLY) | ||
| data.count() | ||
| } | ||
|
|
||
| val mapParallelism = sc.getConf.getInt("spark.default.parallelism", sc.defaultParallelism) | ||
| val reduceParallelism = IOCommon.getProperty("hibench.default.shuffle.parallelism") | ||
| .getOrElse((mapParallelism / 2).toString).toInt | ||
|
|
||
| val postShuffle = repartition(data, reduceParallelism) | ||
| if (disableOutput) { | ||
| postShuffle.foreach(_ => {}) | ||
| } else { | ||
| postShuffle.map { | ||
| case (_, v) => (new Text(v.slice(0, 10)), new Text(v.slice(10, 100))) | ||
| }.saveAsNewAPIHadoopFile[TeraOutputFormat](args(1)) | ||
| } | ||
|
|
||
| sc.stop() | ||
| } | ||
|
|
||
| // More hints on Exceptions | ||
| private def toBoolean(str: String, parameterName: String): Boolean = { | ||
| try { | ||
| str.toBoolean | ||
| } catch { | ||
| case e: IllegalArgumentException => | ||
| throw new IllegalArgumentException( | ||
| s"Unrecognizable parameter ${parameterName}: ${str}, should be true or false") | ||
| } | ||
| } | ||
|
|
||
| // Save a CoalescedRDD than RDD.repartition API | ||
| private def repartition(previous: RDD[Array[Byte]], numReducers: Int): ShuffledRDD[Int, Array[Byte], Array[Byte]] = { | ||
| /** Distributes elements evenly across output partitions, starting from a random partition. */ | ||
| val distributePartition = (index: Int, items: Iterator[Array[Byte]]) => { | ||
| var position = new Random(hashing.byteswap32(index)).nextInt(numReducers) | ||
| items.map { t => | ||
| // Note that the hash code of the key will just be the key itself. The HashPartitioner | ||
| // will mod it with the number of total partitions. | ||
| position = position + 1 | ||
| (position, t) | ||
| } | ||
| } : Iterator[(Int, Array[Byte])] | ||
|
|
||
| // include a shuffle step so that our upstream tasks are still distributed | ||
| new ShuffledRDD[Int, Array[Byte], Array[Byte]](previous.mapPartitionsWithIndex(distributePartition), | ||
| new HashPartitioner(numReducers)) | ||
| } | ||
|
|
||
| } | ||
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.
(new Random(hashing.byteswap32(index)))?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.
I think they are the same. https://github.com/apache/spark/blob/1dce6c1fd45de3d9cf911842f52494051692c48b/core/src/main/scala/org/apache/spark/rdd/RDD.scala#L493