您的位置:首页 > 运维架构

对storm中Topology的并发度理解

2016-01-08 17:08 423 查看
主要思想来源于storm的项目页面: https://github.com/nathanmarz/storm/wiki/Understanding-the-parallelism-of-a-Storm-topology
其中加入了一些个人的理解,所以就把文章mark成原创了,实际上大部分还是人家的东西。其实翻译这个文章的人也挺多,我看了几个,总是感觉有点绕,所以干脆自己总结一下。目标是简单明了的说清楚Storm中Topology在允许过程中的并发机制。当然,目标是好的,具体写出来能否实现目标,就无所谓了,尽力就好:)

---------

概念理解

原文中用了一张图来说明在一个storm cluster中,topology运行时的并发机制。







其实说白了,当一个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)的单位。

并发度的配置

有多种方法可以进行并发度的配置,其优先级如下:
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:

topologyBuilder.setBolt("green-bolt", new GreenBolt(), 2)
.setNumTasks(4)
.shuffleGrouping("blue-spout);


一个运行时的topology的例子








怎么样在运行过程中修改一个topology的并发度

Storm支持在不restart topology的情况下,
动态的改变(增减)worker processes的数目和executors的数目, 称为rebalancing.

主要有两种方法可以rebalance一个topology:

使用Storm web UI 来 rebalance topology.
使用CLI 工具 rebalance topology,一个例子如下:

# Reconfigure the topology "mytopology" to use 5 worker processes,
# the spout "blue-spout" to use 3 executors and
# the bolt "yellow-bolt" to use 10 executors.

$ storm rebalance mytopology -n 5 -e blue-spout=3 -e yellow-bolt=10
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: