关于flink:Flink-任务调度机制几个重要概念

6次阅读

共计 3637 个字符,预计需要花费 10 分钟才能阅读完成。

调度器是 Flink 作业执行的外围组件,治理作业执行的所有相干过程,包含 JobGraph 到 ExecutionGraph 的转换、作业生命周期治理(作业的公布、勾销、进行)、作业的 Task 生命周期治理(Task 的公布、勾销、进行)、资源申请与开释、作业和 Task 的 Failover 等。
调度有几个重要的组件:

调度器:SchedulerNG 及其子类、实现类

调度策略:SchedulingStrategy 及其实现类

调度模式:ScheduleMode 蕴含流和批的调度,有各自不同的调度模式

1、调度器

调度器作用:

1)作业的生命周期治理,如作业的公布、挂起、勾销

2)作业执行资源的申请、调配、开释

3)作业的状态治理,作业公布过程中的状态变动和作业异样时的 FailOver 等

4)作业的信息提供,对外提供作业的详细信息

看一下源码构造:

SchedulerNG.java

public interface SchedulerNG {void setMainThreadExecutor(ComponentMainThreadExecutor mainThreadExecutor); void registerJobStatusListener(JobStatusListener jobStatusListener); void startScheduling(); void suspend(Throwable cause); void cancel(); CompletableFuture<Void> getTerminationFuture(); void handleGlobalFailure(Throwablecause); default boolean updateTaskExecutionState(TaskExecutionState taskExecutionState) {return updateTaskExecutionState(new TaskExecutionStateTransition(taskExecutionState)); } boolean updateTaskExecutionState(TaskExecutionStateTransition taskExecutionState); SerializedInputSplitrequestNextInputSplit(JobVertexID vertexID, ExecutionAttemptIDexecutionAttempt) throws IOException; ExecutionState requestPartitionState(IntermediateDataSetIDintermediateResultId, ResultPartitionID resultPartitionId) throws PartitionProducerDisposedException; void scheduleOrUpdateConsumers(ResultPartitionID partitionID); ArchivedExecutionGraph requestJob(); JobStatus requestJobStatus(); JobDetails requestJobDetails();}
实现类:DefaultScheduler(1.11 移除了 LegacyScheduler)

2、调度行为

SchedulingStrategy.java

/ Component which encapsulates the schedulinglogic. It can react to execution state changes andpartition consumable events. Moreover, it is responsible for resolvingtask failures. /public interface SchedulingStrategy {/ Called when the scheduling is started(initial scheduling operation). 调度入口,触发调度器的调度行为 / void startScheduling(); / Called whenever vertices need to berestarted (due to task failure). 重启执行失败的 Task,个别是 Task 执行异样导致 @param verticesToRestart The tasks need tobe restarted / void restartTasks(Set<ExecutionVertexID> verticesToRestart); / Called whenever an {@link Execution} changesits state. 当 Execution 扭转状态时调用 @param executionVertexId The id of the task @param executionState The new state of theexecution / void onExecutionStateChange(ExecutionVertexID executionVertexId, ExecutionStateexecutionState); /* Called whenever an {@linkIntermediateResultPartition} becomes consumable. 当 IntermediateResultPartition 中的数据能够生产时调用 @param resultPartitionId The id of theresult partition */ void onPartitionConsumable(IntermediateResultPartitionID resultPartitionId);}

3、调度模式

ScheduleMode 决定如何启动 ExecutionGraph 中的 Task。Flink 提供 3 种调度模式:

1)Eager 调度

实用于流计算。一次性申请须要的所有资源,如果资源有余,则作业启动失败。

2)分阶段调度

LAZY_FROM_SOURCES 实用于批处理。从 SourceTask 开始分阶段调度,申请资源的时候,一次性申请本阶段所须要的所有资源。上游 Task 执行结束后开始调度执行上游的 Task,读取上游的数据,执行本阶段的计算工作,执行结束之后,调度后一个阶段的 Task,顺次进行调度,直到作业实现。

3)分阶段 Slot 重用调度

LAZY_FROM_SOURCES_WITH_BATCH_SLOT_REQUEST 实用于批处理。与分阶段调度根本一样,区别在于该模式下应用批处理资源申请模式,能够在资源有余的状况下执行作业,然而须要确保在本阶段的作业执行中没有 Shuffle 行为。

目前眼帘中的 Eager 模式和 LAZY_FROM_SOURCES 模式的资源申请逻辑一样,LAZY_FROM_SOURCES_WITH_BATCH_SLOT_REQUEST 是独自的资源申请逻辑。

ScheduleMode.java

public enum ScheduleMode {LAZY_FROM_SOURCES(true), LAZY_FROM_SOURCES_WITH_BATCH_SLOT_REQUEST(true), EAGER(false); private final boolean allowLazyDeployment; ScheduleMode(booleanallowLazyDeployment) {this.allowLazyDeployment = allowLazyDeployment;} public boolean allowLazyDeployment() { return allowLazyDeployment;}}

4、调度策略

调度策略有三种实现:

EagerSchedulingStrategy:实用于流计算,同时调度所有的 task

LazyFromSourcesSchedulingStrategy:实用于批处理,当输出数据筹备好时(上游解决完)进行 vertices 调度。

PipelinedRegionSchedulingStrategy:以流水线的部分为粒度进行调度

PipelinedRegionSchedulingStrategy 是 1.11 退出的,从 1.12 开始,将以 pipelined region 为单位进行调度。pipelined region 是一组流水线连贯的工作。

这意味着,对于蕴含多个 region 的流作业,在开始部署工作之前,它不再期待所有工作获取 slot。取而代之的是,一旦任何 region 取得了足够的工作 slot 就能够部署它。对于批处理作业,将不会为任务分配 slot,也不会独自部署工作。

取而代之的是,一旦某个 region 取得了足够的 slot,则该工作将与所有其余工作一起部署在同一区域中。

关键词:大数据培训

正文完
 0