Spark Hadoop集群部署与Spark操作HDFS运行详解---Spark学习笔记10

来源:互联网 发布:老九门哪个软件 编辑:程序博客网 时间:2024/06/03 19:24

目前spark的Run on的hadoop版本大多是hadoop2以上,但是实际上各个公司的生产环境不尽相同,用到2.0以上的公司还是少数。

大多数公司还是停留在1代hadoop上,所以我就拿spark0.91 +  hadoop0.20.2-cdh3u5来部署一个小集群,以供测试学习使用。

一、环境概况

Spark集群3台:

web01: slave

web02: master

db01: slave


Hadoop集群:

hadoop 0.20.2-cdh3u5    3台


2、编译Spark

编译spark我在这里就不赘述了,已经有好几篇编译的文章了
第一步、设置Spark要work with的Hadoop的版本号,可以在spark官网查找。
第二部、sbt/sbt assembly 编译发布spark核心包。
还是推荐大家用sbt编译,遇到问题可以看我的spark编译sbt依赖问题。

3、配置


如果编译基本都ok了的话,会在/home/hadoop/shengli/spark/assembly/target/scala-2.10下生成spark和hadoop匹配的发布包。
[java] view plain copy
  1. 总计 92896  
  2. drwxr-xr-x 3 root root     4096 04-21 14:00 cache  
  3. drwxrwxr-x 6 root root     4096 04-21 14:00 ..  
  4. -rw-r--r-- 1 root root 95011766 04-21 14:16 spark-assembly-0.9.1-hadoop0.20.2-cdh3u5.jar  
  5. drwxrwxr-x 3 root root     4096 04-21 14:20 .  

而且在路径/home/hadoop/shengli/spark/lib_managed/jars下,你会找到hadoop-core-0.20.2-cdh3u5.jar这个文件。


4.spark配置


spark官网上提供了好多几种启动集群的方式,我比较推荐的是用官方的shell脚本。sbin/start-all.sh,简单快捷,如果需要定制的启动Master和Slave,就需要用到sbin/start-master.sh   sbin/start-slave.sh了。

4.1 修改spark的spark环境

如果用到这种启动方式,首先要修改配置文件。

[java] view plain copy
  1. cp spark-env.sh.template spark-env.sh  

设置一下Master的IP和端口:(其它的配置以后再配了)
[java] view plain copy
  1. #!/usr/bin/env bash  
  2.   
  3. # This file contains environment variables required to run Spark. Copy it as  
  4. # spark-env.sh and edit that to configure Spark for your site.  
  5. #  
  6. # The following variables can be set in this file:  
  7. # - SPARK_LOCAL_IP, to set the IP address Spark binds to on this node  
  8. # - MESOS_NATIVE_LIBRARY, to point to your libmesos.so if you use Mesos  
  9. # - SPARK_JAVA_OPTS, to set node-specific JVM options for Spark. Note that  
  10. #   we recommend setting app-wide options in the application's driver program.  
  11. #     Examples of node-specific options : -Dspark.local.dir, GC options  
  12. #     Examples of app-wide options : -Dspark.serializer  
  13. #  
  14. # If using the standalone deploy mode, you can also set variables for it here:  
  15. # - SPARK_MASTER_IP, to bind the master to a different IP address or hostname  
  16. # - SPARK_MASTER_PORT / SPARK_MASTER_WEBUI_PORT, to use non-default ports  
  17. # - SPARK_WORKER_CORES, to set the number of cores to use on this machine  
  18. # - SPARK_WORKER_MEMORY, to set how much memory to use (e.g. 1000m, 2g)  
  19. # - SPARK_WORKER_PORT / SPARK_WORKER_WEBUI_PORT  
  20. # - SPARK_WORKER_INSTANCES, to set the number of worker processes per node  
  21. # - SPARK_WORKER_DIR, to set the working directory of worker processes  
  22.   
  23. export SPARK_MASTER_IP=web02.dw  
  24. export SPARK_MASTER_PORT=7077  
  25. export SPARK_WORKER_CORES=4  
  26. export SPARK_WORKER_MEMORY=2g  
  27. export SPARK_WORKER_INSTANCES=2  
  28.   
  29. #control executor mem  
  30. export SPARK_EXECUTOR_MEMORY=1g  
  31. export SPARK_JAVA_OPTS=-Dspark.executor.memory=1g  

4.2 将hadoop配置文件加入classpath

将hadoop配置文件core-site.xml和hdfs-site.xml拷贝到spark/conf下。

4.3 设置slaves

[java] view plain copy
  1. vim slaves  
  2. # A Spark Worker will be started on each of the machines listed below.  
  3. web01.dw  
  4. db01.dw  

4.4分发spark

最基本的默认配置以及配置好了,下面开始分发spark到各个slave节点,注意要先打包后分发,然后到各个节点去解压,不要直接scp。

5. 启动spark

5.1启动spark:

[java] view plain copy
  1. [root@web02 spark]# sbin/start-all.sh   
  2. starting org.apache.spark.deploy.master.Master, logging to /app/home/hadoop/shengli/spark/sbin/../logs/spark-root-org.apache.spark.deploy.master.Master-1-web02.dw.out  
  3. web01.dw: starting org.apache.spark.deploy.worker.Worker, logging to /app/home/hadoop/shengli/spark/sbin/../logs/spark-root-org.apache.spark.deploy.worker.Worker-1-web01.dw.out  
  4. db01.dw: starting org.apache.spark.deploy.worker.Worker, logging to /app/hadoop/shengli/spark/sbin/../logs/spark-root-org.apache.spark.deploy.worker.Worker-1-db01.dw.out  


如上述配置一致:

web02是Master,web01和db01是Worker.

[java] view plain copy
  1. [root@web02 spark]# jps  
  2. 25293 SecondaryNameNode  
  3. 25390 JobTracker  
  4. 18783 Jps  
  5. 25118 NameNode  
  6. 18677 Master  


[java] view plain copy
  1. [root@web01 conf]# jps  
  2. 22733 DataNode  
  3. 5697 Jps  
  4. 22878 TaskTracker  
  5. 5625 Worker  
  6. 4839 jar  

[java] view plain copy
  1. [root@db01 assembly]# jps  
  2. 16242 DataNode  
  3. 16345 TaskTracker  
  4. 30603 Worker  
  5. 30697 Jps  

5.2 web监控

可以清晰的看到:
默认情况下Master的端口为7077,当然我们可以根据配置文件更改,这里暂不做更改。
2个worker,以及每个worker和集群的配置。

Master:

Slaves:




6. spark连接hdfs

6.1启动一个Application

首先我们要先启动一个Application,这个Application就是我们的spark-shell。
[java] view plain copy
  1. SPARK_MASTER=spark://web02.dw:7077  bin/spark-shell  

这里我为了看到DEBUG,修改了conf下的log4j的消息等级为DEBUG。
[java] view plain copy
  1. [root@web02 spark]# SPARK_MASTER=spark://web02.dw:7077  bin/spark-shell  
  2. 14/05/14 17:16:02 INFO HttpServer: Starting HTTP Server  
  3. Welcome to  
  4.       ____              __  
  5.      / __/__  ___ _____/ /__  
  6.     _\ \/ _ \/ _ `/ __/  '_/  
  7.    /___/ .__/\_,_/_/ /_/\_\   version 0.9.1  
  8.       /_/  
  9.   
  10.   
  11. Using Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20)  
  12. Type in expressions to have them evaluated.  
  13. Type :help for more information.  
  14. 14/05/14 17:16:06 INFO Slf4jLogger: Slf4jLogger started  
  15. 14/05/14 17:16:06 INFO Remoting: Starting remoting  
  16. 14/05/14 17:16:06 INFO Remoting: Remoting started; listening on addresses :[akka.tcp://spark@web02.dw:16231]  
  17. 14/05/14 17:16:06 INFO Remoting: Remoting now listens on addresses: [akka.tcp://spark@web02.dw:16231]  
  18. 14/05/14 17:16:06 INFO SparkEnv: Registering BlockManagerMaster  
  19. 14/05/14 17:16:06 INFO DiskBlockManager: Created local directory at /tmp/spark-local-20140514171606-60f2  
  20. 14/05/14 17:16:06 INFO MemoryStore: MemoryStore started with capacity 294.4 MB.  
  21. 14/05/14 17:16:06 INFO ConnectionManager: Bound socket to port 60841 with id = ConnectionManagerId(web02.dw,60841)  
  22. 14/05/14 17:16:06 INFO BlockManagerMaster: Trying to register BlockManager  
  23. 14/05/14 17:16:06 INFO BlockManagerMasterActor$BlockManagerInfo: Registering block manager web02.dw:60841 with 294.4 MB RAM  
  24. 14/05/14 17:16:06 INFO BlockManagerMaster: Registered BlockManager  
  25. 14/05/14 17:16:06 INFO HttpServer: Starting HTTP Server  
  26. 14/05/14 17:16:06 INFO HttpBroadcast: Broadcast server started at http://10.1.8.207:37532  
  27. 14/05/14 17:16:06 INFO SparkEnv: Registering MapOutputTracker  
  28. 14/05/14 17:16:06 INFO HttpFileServer: HTTP File server directory is /tmp/spark-f2865aa6-9bda-4980-a7ff-838f9ae87a18  
  29. 14/05/14 17:16:06 INFO HttpServer: Starting HTTP Server  
  30. 14/05/14 17:16:07 INFO SparkUI: Started Spark Web UI at http://web02.dw:4040  
  31. 14/05/14 17:16:07 INFO AppClient$ClientActor: Connecting to master spark://web02.dw:7077...  
  32. 14/05/14 17:16:07 INFO SparkDeploySchedulerBackend: Connected to Spark cluster with app ID app-20140514171607-0005  
  33. 14/05/14 17:16:07 INFO AppClient$ClientActor: Executor added: app-20140514171607-0005/0 on worker-20140514155706-web01.dw-49813 (web01.dw:49813) with 4 cores  
  34. 14/05/14 17:16:07 INFO SparkDeploySchedulerBackend: Granted executor ID app-20140514171607-0005/0 on hostPort web01.dw:49813 with 4 cores, 1024.0 MB RAM  
  35. 14/05/14 17:16:07 INFO AppClient$ClientActor: Executor added: app-20140514171607-0005/1 on worker-20140514155704-db01.dw-30929 (db01.dw:30929) with 4 cores  
  36. 14/05/14 17:16:07 INFO SparkDeploySchedulerBackend: Granted executor ID app-20140514171607-0005/1 on hostPort db01.dw:30929 with 4 cores, 1024.0 MB RAM  
  37. 14/05/14 17:16:07 INFO AppClient$ClientActor: Executor added: app-20140514171607-0005/2 on worker-20140514155706-db01.dw-60995 (db01.dw:60995) with 4 cores  
  38. 14/05/14 17:16:07 INFO SparkDeploySchedulerBackend: Granted executor ID app-20140514171607-0005/2 on hostPort db01.dw:60995 with 4 cores, 1024.0 MB RAM  
  39. 14/05/14 17:16:07 INFO AppClient$ClientActor: Executor added: app-20140514171607-0005/3 on worker-20140514155704-web01.dw-50163 (web01.dw:50163) with 4 cores  
  40. 14/05/14 17:16:07 INFO SparkDeploySchedulerBackend: Granted executor ID app-20140514171607-0005/3 on hostPort web01.dw:50163 with 4 cores, 1024.0 MB RAM  
  41. 14/05/14 17:16:07 INFO AppClient$ClientActor: Executor updated: app-20140514171607-0005/0 is now RUNNING  
  42. 14/05/14 17:16:07 INFO AppClient$ClientActor: Executor updated: app-20140514171607-0005/1 is now RUNNING  
  43. 14/05/14 17:16:07 INFO AppClient$ClientActor: Executor updated: app-20140514171607-0005/3 is now RUNNING  
  44. 14/05/14 17:16:07 INFO AppClient$ClientActor: Executor updated: app-20140514171607-0005/2 is now RUNNING  
  45. Created spark context..  
  46. Spark context available as sc.  
  47.   
  48.   
  49. scala> 14/05/14 17:16:08 INFO SparkDeploySchedulerBackend: Registered executor: Actor[akka.tcp://sparkExecutor@web01.dw:60575/user/Executor#800679015] with ID 0  
  50. 14/05/14 17:16:08 INFO SparkDeploySchedulerBackend: Registered executor: Actor[akka.tcp://sparkExecutor@web01.dw:3379/user/Executor#1116201144] with ID 3  
  51. 14/05/14 17:16:08 INFO SparkDeploySchedulerBackend: Registered executor: Actor[akka.tcp://sparkExecutor@db01.dw:14501/user/Executor#-1849151050] with ID 1  
  52. 14/05/14 17:16:08 INFO SparkDeploySchedulerBackend: Registered executor: Actor[akka.tcp://sparkExecutor@db01.dw:63875/user/Executor#-1596518942] with ID 2  
  53. 14/05/14 17:16:09 INFO BlockManagerMasterActor$BlockManagerInfo: Registering block manager web01.dw:15040 with 588.8 MB RAM  
  54. 14/05/14 17:16:09 INFO BlockManagerMasterActor$BlockManagerInfo: Registering block manager web01.dw:16038 with 588.8 MB RAM  
  55. 14/05/14 17:16:09 INFO BlockManagerMasterActor$BlockManagerInfo: Registering block manager db01.dw:60398 with 588.8 MB RAM  
  56. 14/05/14 17:16:09 INFO BlockManagerMasterActor$BlockManagerInfo: Registering block manager db01.dw:60074 with 588.8 MB RAM  

这里可以看到其实创建一个Application就要初始化一个SparkContext。
大致流程是:
1. Master启动,启动一个监听端口注册BlockManager。
2. Master注册自己,并创建一个HTTP Server 广播给slaves
3. 注册MapOutputTracker,启动HTTP File Server
4.启动Spark WebUI
5.Client Actor连接上spark://web02.dw:7077
6.每个节点都启动了一个Executor等待执行任务。(有SparkDeploySchedulerBackend完成)
7.创建SparkContext
8.注册slave到BlockManger,主要以内存为单位。

6.2 读取hdfs文件

为了读取hdfs文件,首先要导入hadoop input format,和Writable类包。
然后spark context 的hadoopFile 方法 需要指定格式。见API:
[java] view plain copy
  1. def  
  2. hadoopFile[K, V, F <: InputFormat[K, V]](path: String)(implicit km: ClassTag[K], vm: ClassTag[V], fm: ClassTag[F]): RDD[(K, V)]  
  3. Smarter version of hadoopFile() that uses class tags to figure out the classes of keys, values and the InputFormat so that users don't need to pass them directly. Instead, callers can just write, for example,  
  4.   
  5. val file = sparkContext.hadoopFile[LongWritable, Text, TextInputFormat](path)  
  6. Note: Because Hadoop's RecordReader class re-uses the same Writable object for each record, directly caching the returned RDD will create many references to the same object. If you plan to directly cache Hadoop writable objects, you should first copy them using a map function.  

接下来执行一下:
指定这个文件的格式是k,v格式即PairedRDD,key是longwritable,value是Text,指定读取格式为TextInputFormat,同时也支持sequencefile.
[java] view plain copy
  1. scala> import org.apache.hadoop.mapred._  
  2. import org.apache.hadoop.mapred._  
  3.   
  4. scala> import org.apache.hadoop.io._  
  5. import org.apache.hadoop.io._  
  6.   
  7. scala> val f = sc.hadoopFile[LongWritable, Text, TextInputFormat]("/dw/jyzj_market_trade.txt")  
  8. 14/04/21 17:28:20 INFO MemoryStore: ensureFreeSpace(73490) called with curMem=0, maxMem=308713881  
  9. 14/04/21 17:28:20 INFO MemoryStore: Block broadcast_0 stored as values to memory (estimated size 71.8 KB, free 294.3 MB)  
  10. 14/04/21 17:28:20 DEBUG BlockManager: Put block broadcast_0 locally took  64 ms  
  11. 14/04/21 17:28:20 DEBUG BlockManager: Put for block broadcast_0 without replication took  65 ms  
  12. f: org.apache.spark.rdd.RDD[(org.apache.hadoop.io.LongWritable, org.apache.hadoop.io.Text)] = HadoopRDD[0] at hadoopFile at <console>:18  

执行流程(回头要详细研究一下):
1. MemoryStore首先要确保内存空余空间是否满足
2. Block广播存储在内存中
3. BlockManger将块放入内存了,因为这个文件实在太小了。
4. 没有指定备份
5. 最后f是一个HadoopRDD

接下来看下监控页面已经监控到了程序的运行:


点击appid可以看到执行该app的监控:

这里的确是启动了2个Executor。



点击worker查看worker的运行状态:
看到wb01的Job详情,如果想看到输出,就点击logs下面的stdout。
因为transformation是lazy的,所以要等到计算完action的时候,我们才能看到stdout。

下面我们做什么示范好呢?wordcount吗?怎么每次想到的都是这个,没创意=。=

好吧,要注意我们这个RDD是K,V的。

[java] view plain copy
  1. f.flatMap(_._2.toString().split("\t")).map(word=>(word,1)).reduceByKey(_+_) foreach println  

开了DEBUG模式,谅解- -!
介绍一下流程:
1. 因为访问的是hdfs,要用hadoop用户登录才有权限。
2. Client来连接hdfs,使用ClientProtocol,调用IPC
3. 获取协议Version。
4. 连接到datanode,获取文件的split,这里只有2个。
5.FileInputFormat读取文件。
6.SparkContext开始提交job
7.DAGScheduler开始优化解析执行Stage计划。
8.DaGScheduler对应每个Stage,提交不同的Task任务给Executor执行(执行优先考虑数据本地化)
9.TaskSetManger对Task进行管理序列化task与反序列化Task。有一个Pool来管理taskset。
10.MapOutputTrackerMasterActor被要求发送map output的地址到works的shuffler上。(此步骤在reduce Stage会触发)
11.ShuffleMapTask进行洗牌,因为有reduce的action.计算wordcount
12.最后合并结果输出。

[java] view plain copy
  1. 14/04/21 17:46:26 DEBUG UserGroupInformation: hadoop login  
  2. 14/04/21 17:46:26 DEBUG UserGroupInformation: hadoop login commit  
  3. 14/04/21 17:46:26 DEBUG UserGroupInformation: using local user:UnixPrincipal: root  
  4. 14/04/21 17:46:26 DEBUG UserGroupInformation: UGI loginUser:root (auth:SIMPLE)  
  5. 14/04/21 17:46:26 DEBUG FileSystem: Creating filesystem for hdfs://web02.dw:9000  
  6. 14/04/21 17:46:26 DEBUG Client: The ping interval is60000ms.  
  7. 14/04/21 17:46:26 DEBUG Client: Use SIMPLE authentication for protocol ClientProtocol  
  8. 14/04/21 17:46:26 DEBUG Client: Connecting to web02.dw/10.1.8.207:9000  
  9. 14/04/21 17:46:26 DEBUG Client: IPC Client (47) connection to web02.dw/10.1.8.207:9000 from root: starting, having connections 1  
  10. 14/04/21 17:46:26 DEBUG Client: IPC Client (47) connection to web02.dw/10.1.8.207:9000 from root sending #0  
  11. 14/04/21 17:46:26 DEBUG Client: IPC Client (47) connection to web02.dw/10.1.8.207:9000 from root got value #0  
  12. 14/04/21 17:46:26 DEBUG RPC: Call: getProtocolVersion 55  
  13. 14/04/21 17:46:26 DEBUG DFSClient: Short circuit read is false  
  14. 14/04/21 17:46:26 DEBUG DFSClient: Connect to datanode via hostname is false  
  15. 14/04/21 17:46:26 DEBUG NativeCodeLoader: Trying to load the custom-built native-hadoop library...  
  16. 14/04/21 17:46:26 DEBUG NativeCodeLoader: Failed to load native-hadoop with error: java.lang.UnsatisfiedLinkError: no hadoop in java.library.path  
  17. 14/04/21 17:46:26 DEBUG NativeCodeLoader: java.library.path=  
  18. 14/04/21 17:46:26 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable  
  19. 14/04/21 17:46:26 WARN LoadSnappy: Snappy native library not loaded  
  20. 14/04/21 17:46:26 DEBUG Client: IPC Client (47) connection to web02.dw/10.1.8.207:9000 from root sending #1  
  21. 14/04/21 17:46:26 DEBUG Client: IPC Client (47) connection to web02.dw/10.1.8.207:9000 from root got value #1  
  22. 14/04/21 17:46:26 DEBUG RPC: Call: getFileInfo 72  
  23. 14/04/21 17:46:26 INFO FileInputFormat: Total input paths to process : 1  
  24. 14/04/21 17:46:26 DEBUG Client: IPC Client (47) connection to web02.dw/10.1.8.207:9000 from root sending #2  
  25. 14/04/21 17:46:26 DEBUG Client: IPC Client (47) connection to web02.dw/10.1.8.207:9000 from root got value #2  
  26. 14/04/21 17:46:26 DEBUG RPC: Call: getBlockLocations 4  
  27. 14/04/21 17:46:26 DEBUG FileInputFormat: Total # of splits: 2  
  28. 14/04/21 17:46:26 INFO SparkContext: Starting job: foreach at <console>:21  
  29. 14/04/21 17:46:26 INFO DAGScheduler: Registering RDD 3 (reduceByKey at <console>:21)  
  30. 14/04/21 17:46:26 INFO DAGScheduler: Got job 0 (foreach at <console>:21) with 2 output partitions (allowLocal=false)  
  31. 14/04/21 17:46:26 INFO DAGScheduler: Final stage: Stage 0 (foreach at <console>:21)  
  32. 14/04/21 17:46:26 INFO DAGScheduler: Parents of final stage: List(Stage 1)  
  33. 14/04/21 17:46:26 INFO DAGScheduler: Missing parents: List(Stage 1)  
  34. 14/04/21 17:46:26 DEBUG DAGScheduler: submitStage(Stage 0)  
  35. 14/04/21 17:46:26 DEBUG DAGScheduler: missing: List(Stage 1)  
  36. 14/04/21 17:46:26 DEBUG DAGScheduler: submitStage(Stage 1)  
  37. 14/04/21 17:46:26 DEBUG DAGScheduler: missing: List()  
  38. 14/04/21 17:46:26 INFO DAGScheduler: Submitting Stage 1 (MapPartitionsRDD[3] at reduceByKey at <console>:21), which has no missing parents  
  39. 14/04/21 17:46:26 DEBUG DAGScheduler: submitMissingTasks(Stage 1)  
  40. 14/04/21 17:46:26 INFO DAGScheduler: Submitting 2 missing tasks from Stage 1 (MapPartitionsRDD[3] at reduceByKey at <console>:21)  
  41. 14/04/21 17:46:26 DEBUG DAGScheduler: New pending tasks: Set(ShuffleMapTask(10), ShuffleMapTask(11))  
  42. 14/04/21 17:46:26 INFO TaskSchedulerImpl: Adding task set 1.0 with 2 tasks  
  43. 14/04/21 17:46:26 DEBUG TaskSetManager: Epoch for TaskSet 1.00  
  44. 14/04/21 17:46:26 DEBUG TaskSetManager: Valid locality levels for TaskSet 1.0: NODE_LOCAL, ANY  
  45. 14/04/21 17:46:26 DEBUG DAGScheduler: submitStage(Stage 0)  
  46. 14/04/21 17:46:26 DEBUG DAGScheduler: missing: List(Stage 1)  
  47. 14/04/21 17:46:26 DEBUG DAGScheduler: submitStage(Stage 1)  
  48. 14/04/21 17:46:26 DEBUG TaskSchedulerImpl: parentName: , name: TaskSet_1, runningTasks: 0  
  49. 14/04/21 17:46:26 INFO TaskSetManager: Starting task 1.0:0 as TID 0 on executor 0: db01.dw (NODE_LOCAL)  
  50. 14/04/21 17:46:26 INFO TaskSetManager: Serialized task 1.0:0 as 1896 bytes in 10 ms  
  51. 14/04/21 17:46:26 INFO TaskSetManager: Starting task 1.0:1 as TID 1 on executor 0: db01.dw (NODE_LOCAL)  
  52. 14/04/21 17:46:26 INFO TaskSetManager: Serialized task 1.0:1 as 1896 bytes in 1 ms  
  53. 14/04/21 17:46:26 DEBUG DAGScheduler: submitStage(Stage 0)  
  54. 14/04/21 17:46:26 DEBUG DAGScheduler: missing: List(Stage 1)  
  55. 14/04/21 17:46:26 DEBUG DAGScheduler: submitStage(Stage 1)  
  56. 14/04/21 17:46:26 DEBUG DAGScheduler: submitStage(Stage 0)  
  57. 14/04/21 17:46:26 DEBUG DAGScheduler: missing: List(Stage 1)  
  58. 14/04/21 17:46:26 DEBUG DAGScheduler: submitStage(Stage 1)  
  59. 14/04/21 17:46:27 DEBUG TaskSchedulerImpl: parentName: , name: TaskSet_1, runningTasks: 2  
  60. 14/04/21 17:46:27 DEBUG TaskSchedulerImpl: parentName: , name: TaskSet_1, runningTasks: 1  
  61. 14/04/21 17:46:27 DEBUG TaskSchedulerImpl: parentName: , name: TaskSet_1, runningTasks: 0  
  62. 14/04/21 17:46:28 INFO DAGScheduler: Completed ShuffleMapTask(11)  
  63. 14/04/21 17:46:28 INFO TaskSetManager: Finished TID 1 in 1345 ms on db01.dw (progress: 1/2)  
  64. 14/04/21 17:46:28 INFO TaskSetManager: Finished TID 0 in 1371 ms on db01.dw (progress: 2/2)  
  65. 14/04/21 17:46:28 INFO TaskSchedulerImpl: Removed TaskSet 1.0, whose tasks have all completed, from pool   
  66. 14/04/21 17:46:28 DEBUG DAGScheduler: ShuffleMapTask finished on 0  
  67. 14/04/21 17:46:28 DEBUG DAGScheduler: submitStage(Stage 0)  
  68. 14/04/21 17:46:28 DEBUG DAGScheduler: missing: List(Stage 1)  
  69. 14/04/21 17:46:28 DEBUG DAGScheduler: submitStage(Stage 1)  
  70. 14/04/21 17:46:28 INFO DAGScheduler: Completed ShuffleMapTask(10)  
  71. 14/04/21 17:46:28 DEBUG DAGScheduler: ShuffleMapTask finished on 0  
  72. 14/04/21 17:46:28 INFO DAGScheduler: Stage 1 (reduceByKey at <console>:21) finished in 1.385 s  
  73. 14/04/21 17:46:28 INFO DAGScheduler: looking for newly runnable stages  
  74. 14/04/21 17:46:28 INFO DAGScheduler: running: Set()  
  75. 14/04/21 17:46:28 INFO DAGScheduler: waiting: Set(Stage 0)  
  76. 14/04/21 17:46:28 INFO DAGScheduler: failed: Set()  
  77. 14/04/21 17:46:28 DEBUG MapOutputTrackerMaster: Increasing epoch to 1  
  78. 14/04/21 17:46:28 INFO DAGScheduler: Missing parents for Stage 0: List()  
  79. 14/04/21 17:46:28 INFO DAGScheduler: Submitting Stage 0 (MapPartitionsRDD[5] at reduceByKey at <console>:21), which is now runnable  
  80. 14/04/21 17:46:28 DEBUG DAGScheduler: submitMissingTasks(Stage 0)  
  81. 14/04/21 17:46:28 INFO DAGScheduler: Submitting 2 missing tasks from Stage 0 (MapPartitionsRDD[5] at reduceByKey at <console>:21)  
  82. 14/04/21 17:46:28 DEBUG DAGScheduler: New pending tasks: Set(ResultTask(01), ResultTask(00))  
  83. 14/04/21 17:46:28 INFO TaskSchedulerImpl: Adding task set 0.0 with 2 tasks  
  84. 14/04/21 17:46:28 DEBUG TaskSetManager: Epoch for TaskSet 0.01  
  85. 14/04/21 17:46:28 DEBUG TaskSetManager: Valid locality levels for TaskSet 0.0: ANY  
  86. 14/04/21 17:46:28 DEBUG TaskSchedulerImpl: parentName: , name: TaskSet_0, runningTasks: 0  
  87. 14/04/21 17:46:28 INFO TaskSetManager: Starting task 0.0:0 as TID 2 on executor 1: web01.dw (PROCESS_LOCAL)  
  88. 14/04/21 17:46:28 INFO TaskSetManager: Serialized task 0.0:0 as 1765 bytes in 0 ms  
  89. 14/04/21 17:46:28 INFO TaskSetManager: Starting task 0.0:1 as TID 3 on executor 0: db01.dw (PROCESS_LOCAL)  
  90. 14/04/21 17:46:28 INFO TaskSetManager: Serialized task 0.0:1 as 1765 bytes in 0 ms  
  91. 14/04/21 17:46:28 INFO MapOutputTrackerMasterActor: Asked to send map output locations for shuffle 0 to spark@db01.dw:36699  
  92. 14/04/21 17:46:28 INFO MapOutputTrackerMaster: Size of output statuses for shuffle 0 is 134 bytes  
  93. 14/04/21 17:46:28 DEBUG TaskSchedulerImpl: parentName: , name: TaskSet_0, runningTasks: 2  
  94. 14/04/21 17:46:28 DEBUG TaskSchedulerImpl: parentName: , name: TaskSet_0, runningTasks: 1  
  95. 14/04/21 17:46:28 INFO DAGScheduler: Completed ResultTask(01)  
  96. 14/04/21 17:46:28 INFO TaskSetManager: Finished TID 3 in 286 ms on db01.dw (progress: 1/2)  
  97. 14/04/21 17:46:28 INFO MapOutputTrackerMasterActor: Asked to send map output locations for shuffle 0 to spark@web01.dw:45200  
  98. 14/04/21 17:46:29 DEBUG TaskSchedulerImpl: parentName: , name: TaskSet_0, runningTasks: 0  
  99. 14/04/21 17:46:29 INFO DAGScheduler: Completed ResultTask(00)  
  100. 14/04/21 17:46:29 INFO TaskSetManager: Finished TID 2 in 1019 ms on web01.dw (progress: 2/2)  
  101. 14/04/21 17:46:29 INFO DAGScheduler: Stage 0 (foreach at <console>:21) finished in 1.020 s  
  102. 14/04/21 17:46:29 INFO TaskSchedulerImpl: Removed TaskSet 0.0, whose tasks have all completed, from pool   
  103. 14/04/21 17:46:29 DEBUG DAGScheduler: After removal of stage 0, remaining stages = 1  
  104. 14/04/21 17:46:29 DEBUG DAGScheduler: After removal of stage 1, remaining stages = 0  
  105. 14/04/21 17:46:29 INFO SparkContext: Job finished: foreach at <console>:21, took 2.547314739 s  
  106.   
  107. scala> 14/04/21 17:46:36 DEBUG Client: IPC Client (47) connection to web02.dw/10.1.8.207:9000 from root: closed  
  108. 14/04/21 17:46:36 DEBUG Client: IPC Client (47) connection to web02.dw/10.1.8.207:9000 from root: stopped, remaining connections 0  

结果如图:
第一个slave:


第二个slave:


注意一下,这里执行用了2.5s

如果我把 f 缓存到集群里:

[java] view plain copy
  1. scala> f.cache  
  2. res1: org.apache.spark.rdd.RDD[(org.apache.hadoop.io.LongWritable, org.apache.hadoop.io.Text)] = HadoopRDD[0] at hadoopFile at <console>:18  


再次执行,只用了0.14秒:
[java] view plain copy
  1. 14/04/21 18:14:10 INFO SparkContext: Job finished: foreach at <console>:21, took 0.144185907 s  

这就是Spark的过人之处,暂时写到这里,以后还会继续深入研究spark。



原创文章,转载请注明出处http://blog.csdn.net/oopsoom/article/details/24257981,也不枉我码了这么久的字=。=

—EOF—
原创粉丝点击