Storm Grouping —— 流分組策略


Storm Grouping:

  1. Shuffle Grouping :隨機分組,盡量均勻分布到下游Bolt中

    將流分組定義為混排。這種混排分組意味着來自Spout的輸入將混排,或隨機分發給此Bolt中的任務。shuffle grouping對各個task的tuple分配的比較均勻。

  2. Fields Grouping :按字段分組,按數據中field值進行分組;相同field值的Tuple被發送到相同的Task

    這種grouping機制保證相同field值的tuple會去同一個task,這對於WordCount來說非常關鍵,如果同一個單詞不去同一個task,那么統計出來的單詞次數就不對了。“if the stream is grouped by the “user-id” field, tuples with the same “user-id” will always go to the same task”. —— 小示例

  3. All grouping :廣播

    廣播發送, 對於每一個tuple將會復制到每一個bolt中處理。

  4. Global grouping :全局分組,Tuple被分配到一個Bolt中的一個Task,實現事務性的Topology。

    Stream中的所有的tuple都會發送給同一個bolt任務處理,所有的tuple將會發送給擁有最小task_id的bolt任務處理。

  5. None grouping :不分組

    不關注並行處理負載均衡策略時使用該方式,目前等同於shuffle grouping,另外storm將會把bolt任務和他的上游提供數據的任務安排在同一個線程下

  6. Direct grouping :直接分組 指定分組

    由tuple的發射單元直接決定tuple將發射給那個bolt,一般情況下是由接收tuple的bolt決定接收哪個bolt發射的Tuple。這是一種比較特別的分組方法,用這種分組意味着消息的發送者指定由消息接收者的哪個task處理這個消息。 只有被聲明為Direct Stream的消息流可以聲明這種分組方法。而且這種消息tuple必須使用emitDirect方法來發射。消息處理者可以通過TopologyContext來獲取處理它的消息的taskid (OutputCollector.emit方法也會返回taskid)。

 從task角度看Topology:

  A stream grouping tells a topology how to send tuples between two components. Remember, spouts and bolts execute in parallel as many tasks across the cluster. If you look at how a topology is executing at the task level, it looks something like this:

  問:When a task for Bolt A emits a tuple to Bolt B, which task should it send the tuple to?

  答:A "stream grouping" answers this question by telling Storm how to send tuples between sets of tasks.

Field Grouping:

  A fields grouping lets you group a stream by a subset of its fields. This causes equal values for that subset of fields to go to the same task

  Fields groupings are the basis of implementing streaming joins and streaming aggregations as well as a plethora of other use cases. Underneath the hood, fields groupings are implemented using mod hashing.(stream的合並、聚合、等的基礎;哈希)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM