storm源码之理解Storm中Worker、Executor、Task关系

http://www.cnblogs.com/yufengof/p/storm-worker-executor-task.html

Storm在集群上运行一个Topology时,主要通过以下3个实体来完成Topology的执行工作:

1. Worker( 进程
2. Executor( 线程
3. Task

下图简要描述了这3者之间的关系:


1个worker进程执行的是1个topology的子集( 注:不会出现1个worker为多个topology服务)。1个worker进程会启动1个或多个executor线程来执行1个topology的component(spout或bolt)。因此,1个运行中的topology就是由集群中多台物理机上的多个worker进程组成的。

executor是1个被worker进程启动的单独线程。每个executor只会运行1个topology的1个component(spout或bolt)的task( 注:task可以是1个或多个,storm默认是1个component只生成1个task,executor线程里会在每次循环里顺序调用所有task实例)。

task是最终运行spout或bolt中代码的单元( 注:1个task即为spout或bolt的1个实例,executor线程在执行期间会调用该task的nextTuple或execute方法)。topology启动后,1个component(spout或bolt)的task数目是固定不变的,但该component使用的executor线程数可以动态调整( 例如:1个executor线程可以执行该component的1个或多个task实例)。这意味着,对于1个component存在这样的条件:#threads<=#tasks(即:线程数小于等于task数目)。默认情况下task的数目等于executor线程数目,即1个executor线程只运行1个task。

参考:https://github.com/nathanmarz/storm/wiki/Understanding-the-parallelism-of-a-Storm-topology

猜你喜欢

转载自blog.csdn.net/yongge1981/article/details/79294119