天天看點

Storm-源碼分析- Component ,Executor ,Task之間關系

component包含executor(threads)的個數 

在stormbase中的num-executors, 這對應于你寫topology代碼時, 為每個component指定的并發數(通過setbolt和setspout)

component和task的對應關系, (storm-task-info) 

預設你可以不指定task數, 那麼task和executor為1:1關系 

這個函數, 首先讀出所有components 

最後用遞增序列産生taskid, 并最終生成component和task的對應關系 

如果不設定, task數等于executor數, 後面配置設定就很容易, 否則就涉及task配置設定問題

首先産生system-topology!, 因為system-topology!會增加系統components, acker, systembolt, metricsblot, 這些也都是topology中不可缺少的部分, 是以單純使用使用者定義的topology是不夠的 

然後取出topology裡面所有component

使用thrift/storm-topology-fields從stormtopology的metadata裡面讀出每個fieldid, 并取出value進行merge 

是以結果就是下面3個map, merge在一起的集合 

使用map-value對map中的component進行如下操作 

取出component裡面的componentcomm對象(.getcommon), 并讀出json_conf, 最終讀出conf中topology-tasks

輸出{component-string:tasknum}, 按component-string排序, 再進行mapcat 

{c1 3, c2 2, c3 1} –> (c1,c1,c1,c2,c2,c3) 

再加上遞增編号, into到map, {1 c1, 2 c1, 3 c1, 4 c2, 5 c2, 6 c3} 

topology中, task和executor的配置設定關系, (compute-executors) 

上面已經産生, component->executors 和 component->task, 現在根據component對應的task和executor個數進行task配置設定(到executor) 

預設是1:1配置設定, 但如果設定了task數, 

比如對于c1, 2個executor, 3個tasks [1 2 3], 配置設定結果就是['(1 2) ‘(3)] 

最終to-executor-id, 列出每個executor中task id的範圍([(first task-ids) (last task-ids)])

partition-fixed, 将aseq分成max-num-chunks份 思路,  7整除3, 2餘1  是以, 分成3份, 每份2個, 還餘一個  把這個放到第一份裡面,  是以, 有1份的2+1個, 有(3-1)份的2個 這裡使用integer-divided(7 3), ([3 1] [2 2]) , 剛開始比較難了解, 其實函數名起的不好, 這裡不光除, 已經做了劃分  傳回的結果的意思是, 1份3個, 2份2個 接着就是使用split-at, loop劃分

topology中, executor和component的關系, (compute-executor->component ), 根據(executor:task)關系和(task:component)關系join

最終目的就是獲得executor->component關系, 用于後面的assignment, 其中每個executor包含task範圍[starttask, endtask]

本文章摘自部落格園,原文釋出日期:2013-06-18

繼續閱讀