You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
795 lines
55 KiB
795 lines
55 KiB
6 years ago
|
|
||
|
<!DOCTYPE HTML>
|
||
|
<html lang="zh-hans" >
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||
|
<title>系统架构设计 · 调度系统-EasyScheduler</title>
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||
|
<meta name="description" content="">
|
||
|
<meta name="generator" content="GitBook 3.2.3">
|
||
|
<meta name="author" content="YIGUAN">
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="gitbook/style.css">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="gitbook/gitbook-plugin-insert-logo-link/plugin.css">
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="stylesheet" href="styles/website.css">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<meta name="HandheldFriendly" content="true"/>
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||
|
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
|
||
|
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
|
||
|
|
||
|
|
||
|
|
||
|
<link rel="prev" href="系统使用手册.html" />
|
||
|
|
||
|
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<div class="book">
|
||
|
<div class="book-summary">
|
||
|
|
||
|
|
||
|
<div id="book-search-input" role="search">
|
||
|
<input type="text" placeholder="输入并搜索" />
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<nav role="navigation">
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="summary">
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.1" data-path="./">
|
||
|
|
||
|
<a href="./">
|
||
|
|
||
|
|
||
|
Easyscheduler简介
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2" >
|
||
|
|
||
|
<span>
|
||
|
|
||
|
|
||
|
前端部署文档
|
||
|
|
||
|
</span>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.2.1" data-path="前端部署文档.html">
|
||
|
|
||
|
<a href="前端部署文档.html#前端项目环境构建及编译">
|
||
|
|
||
|
|
||
|
环境搭建
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2" data-path="前端部署文档.html">
|
||
|
|
||
|
<a href="前端部署文档.html#安装及配置">
|
||
|
|
||
|
|
||
|
安装及配置
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.3" data-path="前端部署文档.html">
|
||
|
|
||
|
<a href="前端部署文档.html#项目生产环境配置">
|
||
|
|
||
|
|
||
|
项目生产环境Nginx配置
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.4" data-path="前端部署文档.html">
|
||
|
|
||
|
<a href="前端部署文档.html#前端项目发布">
|
||
|
|
||
|
|
||
|
前端项目发布
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.5" data-path="前端部署文档.html">
|
||
|
|
||
|
<a href="前端部署文档.html#问题">
|
||
|
|
||
|
|
||
|
问题
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.3" >
|
||
|
|
||
|
<span>
|
||
|
|
||
|
|
||
|
后端部署文档
|
||
|
|
||
|
</span>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.3.1" data-path="后端部署文档.html">
|
||
|
|
||
|
<a href="后端部署文档.html#部署文档">
|
||
|
|
||
|
|
||
|
后端部署文档
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.4" data-path="系统使用手册.html">
|
||
|
|
||
|
<a href="系统使用手册.html#使用手册">
|
||
|
|
||
|
|
||
|
系统使用手册
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.5" data-path="系统架构设计.html">
|
||
|
|
||
|
<a href="系统架构设计.html#系统架构设计">
|
||
|
|
||
|
|
||
|
系统架构设计
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.6" >
|
||
|
|
||
|
<span>
|
||
|
|
||
|
|
||
|
前端开发文档
|
||
|
|
||
|
</span>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.6.1" data-path="前端部署文档.html">
|
||
|
|
||
|
<a href="前端部署文档.html">
|
||
|
|
||
|
|
||
|
开发环境搭建
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.6.2" data-path="前端开发文档.html">
|
||
|
|
||
|
<a href="前端开发文档.html#项目目录结构">
|
||
|
|
||
|
|
||
|
项目目录结构
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.6.3" data-path="前端开发文档.html">
|
||
|
|
||
|
<a href="前端开发文档.html#系统功能模块">
|
||
|
|
||
|
|
||
|
系统功能模块
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.6.4" data-path="前端开发文档.html">
|
||
|
|
||
|
<a href="前端开发文档.html#路由和状态管理">
|
||
|
|
||
|
|
||
|
路由和状态管理
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.6.5" data-path="前端开发文档.html">
|
||
|
|
||
|
<a href="前端开发文档.html#规范">
|
||
|
|
||
|
|
||
|
规范
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.6.6" data-path="前端开发文档.html">
|
||
|
|
||
|
<a href="前端开发文档.html#接口">
|
||
|
|
||
|
|
||
|
接口
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.6.7" data-path="前端开发文档.html">
|
||
|
|
||
|
<a href="前端开发文档.html#扩展开发">
|
||
|
|
||
|
|
||
|
扩展开发
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.7" >
|
||
|
|
||
|
<span>
|
||
|
|
||
|
|
||
|
后端开发文档
|
||
|
|
||
|
</span>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.7.1" data-path="任务插件开发.html">
|
||
|
|
||
|
<a href="任务插件开发.html#任务插件开发">
|
||
|
|
||
|
|
||
|
自定义任务插件文档
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<li class="divider"></li>
|
||
|
|
||
|
<li>
|
||
|
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
||
|
本书使用 GitBook 发布
|
||
|
</a>
|
||
|
</li>
|
||
|
</ul>
|
||
|
|
||
|
|
||
|
</nav>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<div class="book-body">
|
||
|
|
||
|
<div class="body-inner">
|
||
|
|
||
|
|
||
|
|
||
|
<div class="book-header" role="navigation">
|
||
|
|
||
|
|
||
|
<!-- Title -->
|
||
|
<h1>
|
||
|
<i class="fa fa-circle-o-notch fa-spin"></i>
|
||
|
<a href="." >系统架构设计</a>
|
||
|
</h1>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<div class="page-wrapper" tabindex="-1" role="main">
|
||
|
<div class="page-inner">
|
||
|
|
||
|
<div id="book-search-results">
|
||
|
<div class="search-noresults">
|
||
|
|
||
|
<section class="normal markdown-section">
|
||
|
|
||
|
<h2 id="系统架构设计">系统架构设计</h2>
|
||
|
<p>在对调度系统架构说明之前,我们先来认识一下调度系统常用的名词</p>
|
||
|
<h3 id="1名词解释">1.名词解释</h3>
|
||
|
<p><strong>DAG:</strong> 全称Directed Acyclic Graph,简称DAG。工作流中的Task任务以有向无环图的形式组装起来,从入度为零的节点进行拓扑遍历,直到无后继节点为止。举例如下图:</p>
|
||
|
<p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/dag_examples_cn.jpg" alt="dag示例" width="60%">
|
||
|
</p><p align="center">
|
||
|
<em>dag示例</em>
|
||
|
</p>
|
||
|
<p></p>
|
||
|
|
||
|
<p><strong>流程定义</strong>:通过拖拽任务节点并建立任务节点的关联所形成的可视化<strong>DAG</strong></p>
|
||
|
<p><strong>流程实例</strong>:流程实例是流程定义的实例化,可以通过手动启动或定时调度生成</p>
|
||
|
<p><strong>任务实例</strong>:任务实例是流程定义中任务节点的实例化,标识着具体的任务执行状态</p>
|
||
|
<p><strong>任务类型</strong>: 目前支持有SHELL、SQL、SUB_PROCESS、PROCEDURE、MR、SPARK、PYTHON、DEPENDENT,同时计划支持动态插件扩展,注意:其中子 <strong>SUB_PROCESS</strong> 也是一个单独的流程定义,是可以单独启动执行的</p>
|
||
|
<p><strong>调度方式:</strong> 系统支持基于cron表达式的定时调度和手动调度。命令类型支持:启动工作流、从当前节点开始执行、恢复被容错的工作流、恢复暂停流程、从失败节点开始执行、补数、调度、重跑、暂停、停止、恢复等待线程。其中 <strong>恢复被容错的工作流</strong> 和 <strong>恢复等待线程</strong> 两种命令类型是由调度内部控制使用,外部无法调用</p>
|
||
|
<p><strong>定时调度</strong>:系统采用 <strong>quartz</strong> 分布式调度器,并同时支持cron表达式可视化的生成</p>
|
||
|
<p><strong>依赖</strong>:系统不单单支持 <strong>DAG</strong> 简单的前驱和后继节点之间的依赖,同时还提供<strong>任务依赖</strong>节点,支持<strong>流程间的自定义任务依赖</strong></p>
|
||
|
<p><strong>优先级</strong> :支持流程实例和任务实例的优先级,如果流程实例和任务实例的优先级不设置,则默认是先进先出</p>
|
||
|
<p><strong>邮件告警</strong>:支持 <strong>SQL任务</strong> 查询结果邮件发送,流程实例运行结果邮件告警及容错告警通知</p>
|
||
|
<p><strong>失败策略</strong>:对于并行运行的任务,如果有任务失败,提供两种失败策略处理方式,<strong>继续</strong>是指不管并行运行任务的状态,直到流程失败结束。<strong>结束</strong>是指一旦发现失败任务,则同时Kill掉正在运行的并行任务,流程失败结束</p>
|
||
|
<p><strong>补数</strong>:补历史数据,支持<strong>区间并行和串行</strong>两种补数方式</p>
|
||
|
<h3 id="2系统架构">2.系统架构</h3>
|
||
|
<h4 id="21-系统架构图">2.1 系统架构图</h4>
|
||
|
<p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/architecture.jpg" alt="系统架构图" width="70%">
|
||
|
</p><p align="center">
|
||
|
<em>系统架构图</em>
|
||
|
</p>
|
||
|
<p></p>
|
||
|
|
||
|
<h4 id="22-架构说明">2.2 架构说明</h4>
|
||
|
<ul>
|
||
|
<li><p><strong>MasterServer</strong> </p>
|
||
|
<p> MasterServer采用分布式无中心设计理念,MasterServer主要负责 DAG 任务切分、任务提交监控,并同时监听其它MasterServer和WorkerServer的健康状态。
|
||
|
MasterServer服务启动时向Zookeeper注册临时节点,通过监听Zookeeper临时节点变化来进行容错处理。</p>
|
||
|
<h5 id="该服务内主要包含">该服务内主要包含:</h5>
|
||
|
<ul>
|
||
|
<li><p><strong>Distributed Quartz</strong>分布式调度组件,主要负责定时任务的启停操作,当quartz调起任务后,Master内部会有线程池具体负责处理任务的后续操作</p>
|
||
|
</li>
|
||
|
<li><p><strong>MasterSchedulerThread</strong>是一个扫描线程,定时扫描数据库中的 <strong>command</strong> 表,根据不同的<strong>命令类型</strong>进行不同的业务操作</p>
|
||
|
</li>
|
||
|
<li><p><strong>MasterExecThread</strong>主要是负责DAG任务切分、任务提交监控、各种不同命令类型的逻辑处理</p>
|
||
|
</li>
|
||
|
<li><p><strong>MasterTaskExecThread</strong>主要负责任务的持久化</p>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li><p><strong>WorkerServer</strong> </p>
|
||
|
<p> WorkerServer也采用分布式无中心设计理念,WorkerServer主要负责任务的执行和提供日志服务。WorkerServer服务启动时向Zookeeper注册临时节点,并维持心跳。</p>
|
||
|
<h5 id="该服务包含:">该服务包含:</h5>
|
||
|
<ul>
|
||
|
<li><p><strong>FetchTaskThread</strong>主要负责不断从<strong>Task Queue</strong>中领取任务,并根据不同任务类型调用<strong>TaskScheduleThread</strong>对应执行器。</p>
|
||
|
</li>
|
||
|
<li><p><strong>LoggerServer</strong>是一个RPC服务,提供日志分片查看、刷新和下载等功能</p>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li><p><strong>ZooKeeper</strong> </p>
|
||
|
<p> ZooKeeper服务,系统中的MasterServer和WorkerServer节点都通过ZooKeeper来进行集群管理和容错。另外系统还基于ZooKeeper进行事件监听和分布式锁。
|
||
|
我们也曾经基于Redis实现过队列,不过我们希望EasyScheduler依赖到的组件尽量地少,所以最后还是去掉了Redis实现。</p>
|
||
|
</li>
|
||
|
<li><p><strong>Task Queue</strong> </p>
|
||
|
<p> 提供任务队列的操作,目前队列也是基于Zookeeper来实现。由于队列中存的信息较少,不必担心队列里数据过多的情况,实际上我们压测过百万级数据存队列,对系统稳定性和性能没影响。</p>
|
||
|
</li>
|
||
|
<li><p><strong>Alert</strong> </p>
|
||
|
<p> 提供告警相关接口,接口主要包括<strong>告警</strong>两种类型的告警数据的存储、查询和通知功能。其中通知功能又有<strong>邮件通知</strong>和<strong>SNMP(暂未实现)</strong>两种。</p>
|
||
|
</li>
|
||
|
<li><p><strong>API</strong> </p>
|
||
|
<p> API接口层,主要负责处理前端UI层的请求。该服务统一提供RESTful api向外部提供请求服务。
|
||
|
接口包括工作流的创建、定义、查询、修改、发布、下线、手工启动、停止、暂停、恢复、从该节点开始执行等等。</p>
|
||
|
</li>
|
||
|
<li><p><strong>UI</strong> </p>
|
||
|
<p> 系统的前端页面,提供系统的各种可视化操作界面,详见<strong><a href="系统使用手册.html">系统使用手册</a></strong>部分。</p>
|
||
|
</li>
|
||
|
</ul>
|
||
|
<h4 id="23-架构设计思想">2.3 架构设计思想</h4>
|
||
|
<h5 id="一、去中心化vs中心化">一、去中心化vs中心化</h5>
|
||
|
<h6 id="中心化思想">中心化思想</h6>
|
||
|
<p>中心化的设计理念比较简单,分布式集群中的节点按照角色分工,大体上分为两种角色:</p>
|
||
|
<p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/master_slave.png" alt="master-slave角色" width="50%">
|
||
|
</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>Master的角色主要负责任务分发并监督Slave的健康状态,可以动态的将任务均衡到Slave上,以致Slave节点不至于“忙死”或”闲死”的状态。</li>
|
||
|
<li>Worker的角色主要负责任务的执行工作并维护和Master的心跳,以便Master可以分配任务给Slave。</li>
|
||
|
</ul>
|
||
|
<p>中心化思想设计存在的问题:</p>
|
||
|
<ul>
|
||
|
<li>一旦Master出现了问题,则群龙无首,整个集群就会崩溃。为了解决这个问题,大多数Master/Slave架构模式都采用了主备Master的设计方案,可以是热备或者冷备,也可以是自动切换或手动切换,而且越来越多的新系统都开始具备自动选举切换Master的能力,以提升系统的可用性。</li>
|
||
|
<li>另外一个问题是如果Scheduler在Master上,虽然可以支持一个DAG中不同的任务运行在不同的机器上,但是会产生Master的过负载。如果Scheduler在Slave上,则一个DAG中所有的任务都只能在某一台机器上进行作业提交,则并行任务比较多的时候,Slave的压力可能会比较大。</li>
|
||
|
</ul>
|
||
|
<h6 id="去中心化">去中心化</h6>
|
||
|
<p align="center" <img="" src="https://analysys.github.io/EasyScheduler/zh_CN/images/decentralization.png" alt="去中心化" width="50%">
|
||
|
</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>在去中心化设计里,通常没有Master/Slave的概念,所有的角色都是一样的,地位是平等的,全球互联网就是一个典型的去中心化的分布式系统,联网的任意节点设备down机,都只会影响很小范围的功能。</li>
|
||
|
<li>去中心化设计的核心设计在于整个分布式系统中不存在一个区别于其他节点的”管理者”,因此不存在单点故障问题。但由于不存在” 管理者”节点所以每个节点都需要跟其他节点通信才得到必须要的机器信息,而分布式系统通信的不可靠行,则大大增加了上述功能的实现难度。</li>
|
||
|
<li>实际上,真正去中心化的分布式系统并不多见。反而动态中心化分布式系统正在不断涌出。在这种架构下,集群中的管理者是被动态选择出来的,而不是预置的,并且集群在发生故障的时候,集群的节点会自发的举行"会议"来选举新的"管理者"去主持工作。最典型的案例就是ZooKeeper及Go语言实现的Etcd。</li>
|
||
|
</ul>
|
||
|
<ul>
|
||
|
<li>EasyScheduler的去中心化是Master/Worker注册到Zookeeper中,实现Master集群和Worker集群无中心,并使用Zookeeper分布式锁来选举其中的一台Master或Worker为“管理者”来执行任务。</li>
|
||
|
</ul>
|
||
|
<h5 id="二、分布式锁实践">二、分布式锁实践</h5>
|
||
|
<p>EasyScheduler使用ZooKeeper分布式锁来实现同一时刻只有一台Master执行Scheduler,或者只有一台Worker执行任务的提交。</p>
|
||
|
<ol>
|
||
|
<li><p>获取分布式锁的核心流程算法如下</p>
|
||
|
<p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/distributed_lock.png" alt="获取分布式锁流程" width="50%">
|
||
|
</p>
|
||
|
</li>
|
||
|
<li><p>EasyScheduler中Scheduler线程分布式锁实现流程图:</p>
|
||
|
<p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/distributed_lock_procss.png" alt="获取分布式锁流程" width="50%">
|
||
|
</p>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
</ol>
|
||
|
<h5 id="三、线程不足循环等待问题">三、线程不足循环等待问题</h5>
|
||
|
<ul>
|
||
|
<li>如果一个DAG中没有子流程,则如果Command中的数据条数大于线程池设置的阈值,则直接流程等待或失败。</li>
|
||
|
<li><p>如果一个大的DAG中嵌套了很多子流程,如下图则会产生“死等”状态:</p>
|
||
|
<p></p><p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/lack_thread.png" alt="线程不足循环等待问题" width="50%">
|
||
|
</p>
|
||
|
上图中MainFlowThread等待SubFlowThread1结束,SubFlowThread1等待SubFlowThread2结束, SubFlowThread2等待SubFlowThread3结束,而SubFlowThread3等待线程池有新线程,则整个DAG流程不能结束,从而其中的线程也不能释放。这样就形成的子父流程循环等待的状态。此时除非启动新的Master来增加线程来打破这样的”僵局”,否则调度集群将不能再使用。<p></p>
|
||
|
</li>
|
||
|
</ul>
|
||
|
<p>对于启动新Master来打破僵局,似乎有点差强人意,于是我们提出了以下三种方案来降低这种风险:</p>
|
||
|
<ol>
|
||
|
<li>计算所有Master的线程总和,然后对每一个DAG需要计算其需要的线程数,也就是在DAG流程执行之前做预计算。因为是多Master线程池,所以总线程数不太可能实时获取。 </li>
|
||
|
<li>对单Master线程池进行判断,如果线程池已经满了,则让线程直接失败。</li>
|
||
|
<li>增加一种资源不足的Command类型,如果线程池不足,则将主流程挂起。这样线程池就有了新的线程,可以让资源不足挂起的流程重新唤醒执行。</li>
|
||
|
</ol>
|
||
|
<p>注意:Master Scheduler线程在获取Command的时候是FIFO的方式执行的。</p>
|
||
|
<p>于是我们选择了第三种方式来解决线程不足的问题。</p>
|
||
|
<h5 id="四、容错设计">四、容错设计</h5>
|
||
|
<p>容错分为服务宕机容错和任务重试,服务宕机容错又分为Master容错和Worker容错两种情况</p>
|
||
|
<h6 id="1-宕机容错">1. 宕机容错</h6>
|
||
|
<p>服务容错设计依赖于ZooKeeper的Watcher机制,实现原理如图:</p>
|
||
|
<p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/fault-tolerant.png" alt="EasyScheduler容错设计" width="40%">
|
||
|
</p>
|
||
|
其中Master监控其他Master和Worker的目录,如果监听到remove事件,则会根据具体的业务逻辑进行流程实例容错或者任务实例容错。
|
||
|
|
||
|
|
||
|
|
||
|
- Master容错流程图:
|
||
|
|
||
|
<p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/fault-tolerant_master.png" alt="Master容错流程图" width="40%">
|
||
|
</p>
|
||
|
ZooKeeper Master容错完成之后则重新由EasyScheduler中Scheduler线程调度,遍历 DAG 找到”正在运行”和“提交成功”的任务,对”正在运行”的任务监控其任务实例的状态,对”提交成功”的任务需要判断Task Queue中是否已经存在,如果存在则同样监控任务实例的状态,如果不存在则重新提交任务实例。
|
||
|
|
||
|
|
||
|
|
||
|
- Worker容错流程图:
|
||
|
|
||
|
<p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/fault-tolerant_worker.png" alt="Worker容错流程图" width="40%">
|
||
|
</p>
|
||
|
|
||
|
<p>Master Scheduler线程一旦发现任务实例为” 需要容错”状态,则接管任务并进行重新提交。</p>
|
||
|
<p> 注意:由于” 网络抖动”可能会使得节点短时间内失去和ZooKeeper的心跳,从而发生节点的remove事件。对于这种情况,我们使用最简单的方式,那就是节点一旦和ZooKeeper发生超时连接,则直接将Master或Worker服务停掉。</p>
|
||
|
<h6 id="2任务失败重试">2.任务失败重试</h6>
|
||
|
<p>这里首先要区分任务失败重试、流程失败恢复、流程失败重跑的概念:</p>
|
||
|
<ul>
|
||
|
<li>任务失败重试是任务级别的,是调度系统自动进行的,比如一个Shell任务设置重试次数为3次,那么在Shell任务运行失败后会自己再最多尝试运行3次</li>
|
||
|
<li>流程失败恢复是流程级别的,是手动进行的,恢复是从只能<strong>从失败的节点开始执行</strong>或<strong>从当前节点开始执行</strong></li>
|
||
|
<li>流程失败重跑也是流程级别的,是手动进行的,重跑是从开始节点进行</li>
|
||
|
</ul>
|
||
|
<p>接下来说正题,我们将工作流中的任务节点分了两种类型。</p>
|
||
|
<ul>
|
||
|
<li><p>一种是业务节点,这种节点都对应一个实际的脚本或者处理语句,比如Shell节点,MR节点、Spark节点、依赖节点等。</p>
|
||
|
</li>
|
||
|
<li><p>还有一种是逻辑节点,这种节点不做实际的脚本或语句处理,只是整个流程流转的逻辑处理,比如子流程节等。</p>
|
||
|
</li>
|
||
|
</ul>
|
||
|
<p>每一个<strong>业务节点</strong>都可以配置失败重试的次数,当该任务节点失败,会自动重试,直到成功或者超过配置的重试次数。<strong>逻辑节点</strong>不支持失败重试。但是逻辑节点里的任务支持重试。</p>
|
||
|
<p>如果工作流中有任务失败达到最大重试次数,工作流就会失败停止,失败的工作流可以手动进行重跑操作或者流程恢复操作</p>
|
||
|
<h5 id="五、任务优先级设计">五、任务优先级设计</h5>
|
||
|
<p>在早期调度设计中,如果没有优先级设计,采用公平调度设计的话,会遇到先行提交的任务可能会和后继提交的任务同时完成的情况,而不能做到设置流程或者任务的优先级,因此我们对此进行了重新设计,目前我们设计如下:</p>
|
||
|
<ul>
|
||
|
<li><p>按照<strong>不同流程实例优先级</strong>优先于<strong>同一个流程实例优先级</strong>优先于<strong>同一流程内任务优先级</strong>优先于<strong>同一流程内任务</strong>提交顺序依次从高到低进行任务处理。</p>
|
||
|
<ul>
|
||
|
<li><p>具体实现是根据任务实例的json解析优先级,然后把<strong>流程实例优先级<em>流程实例id</em>任务优先级_任务id</strong>信息保存在ZooKeeper任务队列中,当从任务队列获取的时候,通过字符串比较即可得出最需要优先执行的任务</p>
|
||
|
<ul>
|
||
|
<li><p>其中流程定义的优先级是考虑到有些流程需要先于其他流程进行处理,这个可以在流程启动或者定时启动时配置,共有5级,依次为HIGHEST、HIGH、MEDIUM、LOW、LOWEST。如下图</p>
|
||
|
<p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/process_priority.png" alt="流程优先级配置" width="40%">
|
||
|
</p>
|
||
|
</li>
|
||
|
<li><p>任务的优先级也分为5级,依次为HIGHEST、HIGH、MEDIUM、LOW、LOWEST。如下图</p>
|
||
|
<p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/task_priority.png" alt="任务优先级配置" width="35%">
|
||
|
</p>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
</ul>
|
||
|
<h5 id="六、logback和grpc实现日志访问">六、Logback和gRPC实现日志访问</h5>
|
||
|
<ul>
|
||
|
<li><p>由于Web(UI)和Worker不一定在同一台机器上,所以查看日志不能像查询本地文件那样。有两种方案:</p>
|
||
|
<ul>
|
||
|
<li>将日志放到ES搜索引擎上</li>
|
||
|
<li>通过gRPC通信获取远程日志信息</li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li><p>介于考虑到尽可能的EasyScheduler的轻量级性,所以选择了gRPC实现远程访问日志信息。</p>
|
||
|
<p align="center">
|
||
|
<img src="https://analysys.github.io/EasyScheduler/zh_CN/images/grpc.png" alt="grpc远程访问" width="50%">
|
||
|
</p>
|
||
|
|
||
|
|
||
|
</li>
|
||
|
</ul>
|
||
|
<ul>
|
||
|
<li>我们使用自定义Logback的FileAppender和Filter功能,实现每个任务实例生成一个日志文件。</li>
|
||
|
<li><p>FileAppender主要实现如下:</p>
|
||
|
<pre><code class="lang-java"><span class="hljs-comment">/**
|
||
|
* task log appender
|
||
|
*/</span>
|
||
|
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TaskLogAppender</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FileAppender</span><<span class="hljs-title">ILoggingEvent</span> </span>{
|
||
|
|
||
|
...
|
||
|
|
||
|
<span class="hljs-meta">@Override</span>
|
||
|
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">append</span><span class="hljs-params">(ILoggingEvent event)</span> </span>{
|
||
|
|
||
|
<span class="hljs-keyword">if</span> (currentlyActiveFile == <span class="hljs-keyword">null</span>){
|
||
|
currentlyActiveFile = getFile();
|
||
|
}
|
||
|
String activeFile = currentlyActiveFile;
|
||
|
<span class="hljs-comment">// thread name: taskThreadName-processDefineId_processInstanceId_taskInstanceId</span>
|
||
|
String threadName = event.getThreadName();
|
||
|
String[] threadNameArr = threadName.split(<span class="hljs-string">"-"</span>);
|
||
|
<span class="hljs-comment">// logId = processDefineId_processInstanceId_taskInstanceId</span>
|
||
|
String logId = threadNameArr[<span class="hljs-number">1</span>];
|
||
|
...
|
||
|
<span class="hljs-keyword">super</span>.subAppend(event);
|
||
|
}
|
||
|
}
|
||
|
</code></pre>
|
||
|
</li>
|
||
|
</ul>
|
||
|
<p>以/流程定义id/流程实例id/任务实例id.log的形式生成日志</p>
|
||
|
<ul>
|
||
|
<li><p>过滤匹配以TaskLogInfo开始的线程名称:</p>
|
||
|
</li>
|
||
|
<li><p>TaskLogFilter实现如下:</p>
|
||
|
<pre><code class="lang-java"><span class="hljs-comment">/**
|
||
|
* task log filter
|
||
|
*/</span>
|
||
|
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TaskLogFilter</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Filter</span><<span class="hljs-title">ILoggingEvent</span> </span>{
|
||
|
|
||
|
<span class="hljs-meta">@Override</span>
|
||
|
<span class="hljs-function"><span class="hljs-keyword">public</span> FilterReply <span class="hljs-title">decide</span><span class="hljs-params">(ILoggingEvent event)</span> </span>{
|
||
|
<span class="hljs-keyword">if</span> (event.getThreadName().startsWith(<span class="hljs-string">"TaskLogInfo-"</span>)){
|
||
|
<span class="hljs-keyword">return</span> FilterReply.ACCEPT;
|
||
|
}
|
||
|
<span class="hljs-keyword">return</span> FilterReply.DENY;
|
||
|
}
|
||
|
}
|
||
|
</code></pre>
|
||
|
</li>
|
||
|
</ul>
|
||
|
<h3 id="总结">总结</h3>
|
||
|
<p>本文从调度出发,初步介绍了大数据分布式工作流调度系统--EasyScheduler的架构原理及实现思路。未完待续</p>
|
||
|
|
||
|
|
||
|
</section>
|
||
|
|
||
|
</div>
|
||
|
<div class="search-results">
|
||
|
<div class="has-results">
|
||
|
|
||
|
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
|
||
|
<ul class="search-results-list"></ul>
|
||
|
|
||
|
</div>
|
||
|
<div class="no-results">
|
||
|
|
||
|
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
<a href="系统使用手册.html#使用手册" class="navigation navigation-prev navigation-unique" aria-label="Previous page: 系统使用手册">
|
||
|
<i class="fa fa-angle-left"></i>
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<script>
|
||
|
var gitbook = gitbook || [];
|
||
|
gitbook.push(function() {
|
||
|
gitbook.page.hasChanged({"page":{"title":"系统架构设计","level":"1.5","depth":1,"next":{"title":"前端开发文档","level":"1.6","depth":1,"ref":"","articles":[{"title":"开发环境搭建","level":"1.6.1","depth":2,"path":"前端部署文档.md","ref":"前端部署文档.md","articles":[]},{"title":"项目目录结构","level":"1.6.2","depth":2,"anchor":"#项目目录结构","path":"前端开发文档.md","ref":"前端开发文档.md#项目目录结构","articles":[]},{"title":"系统功能模块","level":"1.6.3","depth":2,"anchor":"#系统功能模块","path":"前端开发文档.md","ref":"前端开发文档.md#系统功能模块","articles":[]},{"title":"路由和状态管理","level":"1.6.4","depth":2,"anchor":"#路由和状态管理","path":"前端开发文档.md","ref":"前端开发文档.md#路由和状态管理","articles":[]},{"title":"规范","level":"1.6.5","depth":2,"anchor":"#规范","path":"前端开发文档.md","ref":"前端开发文档.md#规范","articles":[]},{"title":"接口","level":"1.6.6","depth":2,"anchor":"#接口","path":"前端开发文档.md","ref":"前端开发文档.md#接口","articles":[]},{"title":"扩展开发","level":"1.6.7","depth":2,"anchor":"#扩展开发","path":"前端开发文档.md","ref":"前端开发文档.md#扩展开发","articles":[]}]},"previous":{"title":"系统使用手册","level":"1.4","depth":1,"anchor":"#使用手册","path":"系统使用手册.md","ref":"系统使用手册.md#使用手册","articles":[]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","insert-logo-link","livereload"],"styles":{"website":"./styles/website.css"},"pluginsConfig":{"livereload":{},"insert-logo-link":{"src":"http://geek.analysys.cn/static/upload/236/2019-03-29/379450b4-7919-4707-877c-4d33300377d4.png","url":"https://github.com/analysys/EasyScheduler"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"YIGUAN","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"调度系统-EasyScheduler","language":"zh-hans","gitbook":"3.2.3","description":"调度系统"},"file":{"path":"系统架构设计.md","mtime":"2019-04-08T02:29:28.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-04-10T07:14:01.407Z"},"basePath":".","book":{"language":""}});
|
||
|
});
|
||
|
</script>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<script src="gitbook/gitbook.js"></script>
|
||
|
<script src="gitbook/theme.js"></script>
|
||
|
|
||
|
|
||
|
<script src="gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
<script src="gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
<script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
<script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
<script src="gitbook/gitbook-plugin-search/search.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
<script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
<script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
<script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
<script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
|
||
|
|
||
|
|
||
|
|
||
|
</body>
|
||
|
</html>
|
||
|
|