Storm学习总结——基础篇

2019-03-02 23:45|来源: 网路

Storm简介

  属性:    分布式流计算框架。

  类似产品:  Yahoo!的S4

  特点:    开源,分布式,实时计算系统,可扩展,高容错,处理速度快,支持多语言编程。

Storm集群结构

Storm基本概念

1 Topology

  原始定义:To do realtime computation on Storm, you create what are called "topologies". A topology is a graph of computation. Each node in a topology contains processing logic, and links between nodes indicate how data should be passed around between nodes.

  一个topology是spouts和bolts组成的图。

  功能类似于Hadoop中的 MRJob

    一个Topology在生成后一直存在,其上面的每个节点对流入的数据进行处理,并将处理结果流出到下游。

2 Stream(流)

  定义为无限的tuple序列。(Tuple可以理解为:命名的value序列, 可以理解成Key/value序列, 每个value可以是任何类型)。

  在声明一个Stream时,会给它一个标识性的ID(如果没有指定,则ID默认为default).

3 Spout(流的源头)

  Generally spouts will read tuples from an external source and emit them into the topology 。

  Spouts can either be reliable(可靠的,如果后续节点处理某个Tuple失败,Spout会重新发送该Tuple) or unreliable(非可靠的)。

  Spout可以同时发送tuple 到指定id的stream(通过OutputFieldsDeclarer中的declareStream method来定义)。

4 Bolt(流的处理节点)

  All processing in topologies is done in bolts. Bolts can do anything from filtering, functions, aggregations, joins, talking to databases, and more.

  Bolts can emit more than one stream. To do so, declare multiple streams using the declareStream method of OutputFieldsDeclarer and specify the stream to emit to when using the emit method on OutputCollector.

  The main method in bolts is the execute method which takes in as input a new tuple. Bolts emit new tuples using the OutputCollector object. Bolts must call the ack method on the OutputCollector for every tuple they process so that Storm knows when tuples are completed. For the common case of processing an input tuple, emitting 0 or more tuples based on that tuple, and then acking the input tuple (Storm provides an IBasicBolt interface which does the acking automatically).

  

5 Stream groupings

  

  

  A stream grouping defines how that stream should be partitioned among the bolt's tasks.

  每一个spout和bolt会被当作很多task在整个集群里执行。每一个executor 对应到一个线程,在这个线程上运行多个task,而stream grouping则是定义怎么从一堆task发射tuple到另外一堆task。

  

  注意:上面的描述仅对于上游的spout或 bolt如何分配tuple给下一个bolt的不同task而言的。

 

Storm Topology 并发度的理解

  

  一个Topology可以包含一个或多个worker(并行的跑在不同的machine上), 所以worker process就是执行一个topology的子集, 并且worker只能对应于一个topology

  一个worker可用包含一个或多个executor, 每个component (spout或bolt)至少对应于一个executor, 所以可以说executor执行一个compenent的子集, 同时一个executor只能对应于一个component

  Task就是具体的处理逻辑, 一个executor线程可以执行一个或多个tasks ,但一般默认每个executor只执行一个task(所以我们往往认为task就是执行线程, 其实不然)

 

  对于并发度的配置, 在storm里面可以在多个地方进行配置:

  worker processes的数目, 可以通过配置文件和代码中配置, worker就是执行进程, 所以考虑并发的效果, 数目至少应该大于machines的数目

  executor的数目, component的并发线程数,只能在代码中配置(通过setBolt和setSpout的参数), 例如, setBolt("green-bolt", new GreenBolt(), 2)

  tasks的数目, 可以不配置, 默认和executor1:1, 也可以通过setNumTasks()配置

 

  

  

 

运行Topology 

  1) 本地模式:

  storm用一个进程里面的线程来模拟所有的spout和bolt. 本地模式对开发和测试来说比较有用。 你运行storm-starter里面的topology的时候它们就是以本地模式运行的, 你可以看到topology里面的每一个组件在发射什么消息。

  2) 分布式模式:

  storm由一堆机器组成。当你提交topology给master的时候, 你同时也把topology的代码提交了。master负责分发你的代码并且负责给你的topolgoy分配工作进程。如果一个工作进程挂掉了, master节点会把认为重新分配到其它节点

 

 

 

 

 

 

 

 

 

 

  


转自:http://www.cnblogs.com/mailzyw/p/3338756

相关问答

更多