Spark的启动进程详解

Master和Worker是执行任务之前存在的进程 (类似于公司)

Driver和Excutor是任务执行之后存在的进程(类似于公司接到项目后才成立的项目小组)

启动步骤:

  1. 启动Master资源管理进程和Work进程
  2. 有任务来执行时会启动Driver进程,然后向Master资源管理进程进行注册并申请资源
  3. Master资源管理进程分配资源给Worker进程
  4. Work进程开启Executor进程, Worker进程向Master进程报告Executor的状态
  5. Executor(持有Driver对象引用)在启动开始时会先向Driver进行注册,

注测的目的:

  1. 将执行的Executor放入到Driver的Executor集合中,以便Executor发出心跳检测信号和Driver进行接收并更新时间后, 进行超时检测
  2. Driver划分任务后可以分配任务给Driver
  3. Executor注册完毕后, Driver会划分任务(Task),然后调度任务(Task)给注册的Executor去执行
  4. Executor执行任务(Task)时会向Driver报告任务执行状态,直到执行完
  5. 任务执行完后,Executor进程会消失, 最后Driver进程也会向Master进程进行注销

转载于:https://www.cnblogs.com/huangleshu/p/10121521.html

### Apache Spark 启动全过程详解 Apache Spark启动过程涉及多个组件之间的交互,主要包括集群管理器的选择、Driver 和 Executor 的初始化以及资源分配等阶段。以下是 Spark 启动过程的技术细节: #### 1. 集群模式选择 Spark 支持多种部署方式,包括 Standalone 模式、YARN 模式、Mesos 模式和 Kubernetes 模式。用户可以在提交应用时通过 `--master` 参数指定集群管理模式。例如,在 YARN 上运行的应用程序可以通过设置 `yarn-client` 或 `yarn-cluster` 来决定 Driver 是否在客户端运行。 当用户提交一个 Spark 应用时,Spark 提交脚本(如 `spark-submit`)会解析配置文件并根据所选的 Master URL 初始化相应的环境[^1]。 #### 2. SparkContext 创建 在应用程序中,开发者通常通过创建 `SparkSession` 或者更底层的 `SparkContext` 对象来启动 Spark 应用。这一阶段的主要工作如下: - **加载配置**:从默认配置文件(如 `conf/spark-defaults.conf`)、命令行参数或者动态设定的属性中加载 Spark 配置。 - **初始化调度器**:创建 TaskScheduler 并注册到 Cluster Manager 中。TaskScheduler 负责任务分发,而 DAGScheduler 则负责将逻辑计划转化为物理执行计划。 - **绑定监听器**:为事件总线绑定各种 Listener,用于监控作业进度和其他元数据更新。 ```scala val conf = new SparkConf().setAppName("MyApp").setMaster("local[*]") val sc = new SparkContext(conf) ``` #### 3. 注册至集群管理器 一旦 SparkContext 成功构建完成之后,它便会尝试联系选定好的 Resource Manager (RM),比如对于 standalone cluster mode 下来说就是 master node;而在 yarn client/server modes 当中则是 ResourceManager daemon 运行所在位置。此时 driver program 将发送 register request 请求告知 RM 自己的存在状态及其所需资源规格信息(cores, memory etc.)以便后续安排 executors 实例化事宜[^4]。 #### 4. Executors 分配与启动 Cluster Manager 接收到 RegisterApplication 消息后,依据当前系统的负载情况以及其他约束条件(像 locality preferences),逐步批准申请并将实际可用 slot 数量反馈给 Client Side(Driver Process)。随后便进入 LaunchExecutor phase —— 即由 Worker Nodes 执行特定 shell script 去实例化 java process 形式的 worker threads(pool size determined by parameter settings like 'spark.executor.cores') ,从而形成完整的 distributed computing framework structure. 值得注意的是,在整个生命周期里,除非显式终止 session/stop context operation 发生之前,所有已分配出去 resources including both cpu time slots alongside corresponding physical memories will be reserved exclusively dedicated solely towards serving this single job only without interruption unless otherwise specified beforehand via advanced tuning parameters such as dynamic allocation mechanism enabled under certain circumstances.[^1] #### 5. 数据处理流程 随着 executor nodes 正常上线运作起来以后,接下来便是围绕 input datasets 展开的一系列 transformation & action operations 定义出来的 pipeline execution chain 。每当遇到某个 stage boundary point where shuffling becomes necessary due to key-value pair redistributions across partitions boundaries , system automatically triggers another round of resource negotiation processes similar described above but specifically targeting those newly generated intermediate results files stored temporarily within local filesystem directories managed separately per individual tasks involved during previous stages executions . 最后值得一提提一下 shuffle read/write mechanisms implemented inside block manager components which play crucial roles ensuring efficient data transfers between different machines located geographically far away from each other yet still maintaining high performance levels thanks largely contributed efforts made possible through sophisticated algorithms designed around network protocols selection strategies mentioned earlier regarding netty vs nio implementations choices affecting overall latencies experienced throughout entire end-to-end pipelines constructed based upon user supplied business logics encoded into their custom written map/reduce functions bodies passed along side regular api calls sequences invoked sequentially following standard library conventions established over years development iterations cycles continuously improving codebases maintained actively open source communities worldwide today ![^3] --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值