分享

Storm总结-关于Storm 中Topology的并发度的理解

xioaxu790 发表于 2014-10-20 19:46:28 [显示全部楼层] 只看大图 回帖奖励 阅读模式 关闭右栏 3 14472
问题导读
1、你如何理解topology运行时的并发机制?
2、怎么样在运行过程中修改一个topology的并发度?
3、有哪些方法可以修改topology运行时的并发机制?






其中加入了一些个人的理解,所以就把文章mark成原创了,实际上大部分还是人家的东西。其实翻译这个文章的人也挺多,我看了几个,总是感觉有点绕,所以干脆自己总结一下。目标是简单明了的说清楚Storm中Topology在允许过程中的并发机制。当然,目标是好的,具体写出来能否实现目标,就无所谓了,尽力就好:)

---------

概念理解
原文中用了一张图来说明在一个storm cluster中,topology运行时的并发机制。
1.png



其实说白了,当一个topology在storm cluster中运行时,它的并发主要跟3个逻辑实体想过:worker,executor 和task

1. Worker 是运行在工作节点上面,被Supervisor守护进程创建的用来干活的进程。每个Worker对应于一个给定topology的全部执行任务的一个子集。反过来说,一个Worker里面不会运行属于不同的topology的执行任务。

2. Executor可以理解成一个Worker进程中的工作线程。一个Executor中只能运行隶属于同一个component(spout/bolt)的task。一个Worker进程中可以有一个或多个Executor线程。在默认情况下,一个Executor运行一个task。

3. Task则是spout和bolt中具体要干的活了。一个Executor可以负责1个或多个task。每个component(spout/bolt)的并发度就是这个component对应的task数量。同时,task也是各个节点之间进行grouping(partition)的单位。


并发度的配置
有多种方法可以topology运行时的并发机制,其优先级如下:
defaults.yaml < storm.yaml < topology 私有配置 < component level(spout/bolt) 的私有配置

至于具体怎么配置,至今拷贝过来大家看看便知:

设置worker数量
Description: 在当前storm cluster中给这个topology创建的worker数量
Configuration option: TOPOLOGY_WORKERS
How to set in your code (examples):
Config#setNumWorkers


设置executor数量
Description: 给指定component创建的executor数量
Configuration option: ?
How to set in your code (examples):
TopologyBuilder#setSpout()

TopologyBuilder#setBolt()

Note that as of Storm 0.8 the parallelism_hint parameter now specifies the initial number of executors (not tasks!) for that bolt.

设置task数量
Description: 给指定 component 创建的task数量
Configuration option: TOPOLOGY_TASKS
How to set in your code (examples):
ComponentConfigurationDeclarer#setNumTasks()

Here is an example code snippet to show these settings in practice:
  1. topologyBuilder.setBolt("green-bolt", new GreenBolt(), 2)
  2.                .setNumTasks(4)
  3.                .shuffleGrouping("blue-spout);
复制代码




一个运行时的topology的例子
example-of-a-running-topology.png



怎么样在运行过程中修改一个topology的并发度
Storm支持在不restart topology的情况下, 动态的改变(增减)worker processes的数目和executors的数目, 称为rebalancing.
主要有两种方法可以rebalance一个topology:

使用Storm web UI 来 rebalance topology.
使用CLI 工具 rebalance topology,一个例子如下:
  1. # Reconfigure the topology "mytopology" to use 5 worker processes,
  2. # the spout "blue-spout" to use 3 executors and
  3. # the bolt "yellow-bolt" to use 10 executors.
  4. $ storm rebalance mytopology -n 5 -e blue-spout=3 -e yellow-bolt=10
复制代码




主要思想来源于storm的项目页面: https://github.com/nathanmarz/st ... of-a-Storm-topology

已有(3)人评论

跳转到指定楼层
caiyifeng 发表于 2014-12-17 23:24:47
多谢楼主分享
回复

使用道具 举报

cdb521007 发表于 2015-7-25 23:31:04
感谢楼主分享经验,学习了
回复

使用道具 举报

chimes298 发表于 2015-10-29 00:34:10
感谢楼主,如果一个节点上运行两个topology,每个使用10个worker,slot是不是应该设置为20?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条