一.Scheduler概述
Scheduler是Storm的调度器, 它负责为Topology分配当前集群中可用的资源。 Storm定义了IScheduler接口, 用户可以通过实现该接口来定义自己的Scheduler。 Storm提供了几种Scheduler,分别是EvenScheduler、 DefaultScheduler和IsolationScheduler,Pluggable Schedule,MultitenantScheduler,ResourceAwareScheduler 下面简要介绍一下它们。
1.EvenScheduler:
会将系统中的可用资源均匀地分配给当前需要任务分配的多个Topology。
2.DefaultScheduler:
跟EvenScheduler基本一致, 唯一的区别在于它会在为Topology分配任务之前先释放掉其他Topology不再需要的资源, 然后调用EventScheduler方法为Topology均匀分配资源。
3.IsolationScheduler:
它提供了一种机制, 使得用户可以单独为某些Topology指定它们需要的机器资源( 机器数目 )。 用户需要在Storm配置项中指定这些信息( topology-name及其所需的机器数目 ), IsolationScheduler会优先对这些Topology分配任务, 保证分配给某个Topology的机器只能运行这个特定的Topology, 相当于这些Topology的运行环境是相互独立的。 待这些指定的Topology分配完成之后, 再调用DefaultScheduler, 利用系统中剩余的资源为剩余的Topology进行任务分配。
4.Pluggable Schedule:
可插拔式的任务分配器,编写自己的task分配算法,实现自己的调度器来替代默认的调度器去分配executors给workers。在storm.yaml文件里指定storm.scheduler,自定义的调度器要实现IScheduler接口。
5.MultitenantScheduler:
这种调度模式会为每个topology发布者构造一个自己专属的隔离资源池,之后会通过遍历topology集,通过为资源池分配topology关联来分配节点。
6. ResourceAwareScheduler:
资源感知调度器可以在每个用户的基础上分配资源。 每个用户可以保证一定数量的资源来运行他或她的 topology,并且资源感知调度器将尽可能满足这些保证。 当 Storm 群集具有额外的免费资源时,资源感知调度器将能够以公平的方式为用户分配额外的资源。
二.Scheduler接口
如果用户想要自定义Scheduler,需要实现ISheduler接口,该接口是Storm定义的为集群当前所有Topology分配任务的接口,它的定义如下...
public interface IScheduler {
void prepare(Map conf);
/**
* Set assignments for the topologies which needs scheduling. The new assignments is available
* through <code>cluster.getAssignments()</code>
*
*@param topologies all the topologies in the cluster, some of them need schedule. Topologies object here
* only contain static information about topologies. Information like assignments, slots are all in
* t