Spark编程指南之四:Spark分布式集群模式的运行时系统架构

官方集群模式介绍

Spark官方网站http://spark.apache.org的Deploying菜单下给出了集群模式
的简单介绍(可查看http://spark.apache.org/docs/latest/cluster-overview.html):
由SparkContext对接多种Cluster Managers(Standalone,Mesoscale或者YARN),用来分配资源。
分配资源后在集群内启动executors,SparkContext再将程序jar包发送到各个Executor上,最后将task发送到Executor上执行。如下图:
来源:http://spark.apache.org/docs/latest/cluster-overview.html
总体来说:Spark应用程序的运行架构由三部分组成:SparkContext、Cluster Manager、Executor。
1、SparkContext负责作业的全生命周期管理
2、Cluster Manager进行资源的分配和管理,不同模式下由不同的角色负责提供。在Local和Standalone模式下由Master提供;在YARN模式下由Resource Manager提供;在Mesos模式下由Mesos Manager提供。
3、Executor是每个应用程序的专属进程,运行在自己的JVM中。
注:不同Spark程序数据不是共享的

Cluster Manager有哪些?

Standalone

– Spark自带的简单的集群资源管理(a simple cluster manager included with Spark that makes it easy to set up a cluster.)

Apache Mesos

– 通用的可以跑MapReduce的集群管理(a general cluster manager that can also run Hadoop MapReduce and service applications.)

Hadoop YARN

– Hadoop2的resource manager(the resource manager in Hadoop 2.)

Kubernetes

– 容器应用的开源管理器(an open-source system for automating deployment, scaling, and management of containerized applications.)

Standalone模式架构与作业执行流程

Standalone模式(独立模式)是Spark自身实现的资源调度框架,由客户端、Master节点和Worker节点组成。此模式下Master即为Cluster Manager。
SparkContext既可以运行在客户端,也可以运行在Master。当使用Spark-Submit工具提交或在Eclipse、IDEA等开发平台上运行作业时,SparkContext是运行在本地客户端;当使用Spark-Shell交互式工具提交或使用run-example脚本来运行时,SparkContext在Master节点运行。
调度过程可分为申请资源、分配资源、注册、分配任务、执行任务几个步骤。

申请资源

Spark应用程序从驱动程序Driver开始,Driver创建SparkContext来连接集群并调度任务。
Driver会生成有向无环图DAG,通过一定的优化,进行程序的规划。
Driver向Master申请Executer资源
(其中的Driver进程,当用Client模式提交的时候,运行在Client的机器上。如果是集群模式提交,运行在其中一台Worker节点上。)

分配资源

Master向Driver返回资源

注册

Executor向Driver进行注册并申请Task

发送任务

Driver的DAGScheduler解析作业并生成相应的Stage,每个Stage包含的Task通过TaskScheduler分配给Executor执行。

执行任务

Executor负责运行Task,并负责将数据存在内存或者磁盘上。
Executor会启动线程池,启动多个线程。
Executor在Worker节点上,获取CPU和内存等计算资源,默认占用所有CPU和内存。

参考链接

http://spark.apache.org/docs/latest/cluster-overview.html
http://spark.apache.org/docs/latest/submitting-applications.html
http://www.cnblogs.com/tgzhu/p/5818374.html

猜你喜欢

转载自blog.csdn.net/weixin_42628594/article/details/85455587