当创建一个SparkContext时就会创建一个SparkConf实例。
优先级最高的是在用户代码中显示调用set()方法设置选项;
其次是通过spark-submit传递的参数;
再次是写在配置文件里的值;
最后是系统的默认值。
需求:使用Spark shell完成简单的日志分析应用。
scala> val input =sc.textFile("/home/spark01/Documents/input.text")
input: org.apache.spark.rdd.RDD[String] = MapPartitionsRDD[3] at textFile at <console>:27
scala> val tokenized = input.map(line=>line.split(" ")).filter(words=>words.size>0)
tokenized: org.apache.spark.rdd.RDD[Array[String]] = MapPartitionsRDD[5] at filter at <console>:29
scala> val counts = tokenized.map(words=>(words(0),1)).reduceByKey{(a,b)=>a+b}
counts: org.apache.spark.rdd.RDD[(String, Int)] = ShuffledRDD[7] at reduceByKey at <console>:31
scala> // see RDD
scala> input.toDebugString
res0: String =
(1) MapPartitionsRDD[3] at textFile at <console>:27 []
| /home/spark01/Documents/input.text HadoopRDD[2] at textFile at <console>:27 []
scala> counts.toDebugString
res1: String =
(1) ShuffledRDD[7] at reduceByKey at <console>:31 []
+-(1) MapPartitionsRDD[6] at map at <console>:31 []
| MapPartitionsRDD[5] at filter at <console>:29 []
| MapPartitionsRDD[4] at map at <console>:29 []
| MapPartitionsRDD[3] at textFile at <console>:27 []
| /home/spark01/Documents/input.text HadoopRDD[2] at textFile at <console>:27 []
scala> counts.collect()
res2: Array[(String, Int)] = Array((ERROR,1), (##input.text##,1), (INFO,4), ("",2), (WARN,2))
scala> counts.cache()
res3: counts.type = ShuffledRDD[7] at reduceByKey at <console>:31
scala> counts.collect()
res5: Array[(String, Int)] = Array((ERROR,1), (##input.text##,1), (INFO,4), ("",2), (WARN,2))
scala>
默认情况地址是http://localhost:4040
通过浏览器可以查看已经运行过的作业(job)的详细情况
如图下图:
图1所有任务用户界面
图二作业2详细信息用户界面
代码层面:并行度、序列化格式、内存管理
运行环境:硬件供给。