Storm學習總結-基礎篇

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節點會把認爲重新分配到其它節點

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章