Storm中涉及到了不少組件,例如nimbus,supervisor等等,在參考了這兩篇文章以後,對這個有了更好的理解。html
Understanding the parallelism of a Storm topologynode
https://github.com/nathanmarz/storm/wiki/Understanding-the-parallelism-of-a-Storm-topologygit
http://www.cnblogs.com/yufengof/p/storm-worker-executor-task.htmlgithub
咱們先理一下概念:編程
這樣一說就有點亂,由於這個worker、executor、task和topology,spout和bolt之間又是怎麼樣的對應關係呢??併發
首先看下面一張圖函數
supervisor和node是一一對應的關係,而worker就是process(進程),executor就是thread(線程),task就是在spout或bolt中定義的函數。ui
這樣就好理解了,這些從上到下都是一對多的關係。編碼
那supervisor,worker和executor跟topology或component(包括spout和bolt)之間的對應關係呢?spa
咱們看storm wiki中的一張圖片來解釋
對於這個topology,
1 Config conf = new Config(); 2 conf.setNumWorkers(2); // use two worker processes 3 4 topologyBuilder.setSpout("blue-spout", new BlueSpout(), 2); // set parallelism hint to 2 5 6 topologyBuilder.setBolt("green-bolt", new GreenBolt(), 2) 7 .setNumTasks(4) 8 .shuffleGrouping("blue-spout"); 9 10 topologyBuilder.setBolt("yellow-bolt", new YellowBolt(), 6) 11 .shuffleGrouping("green-bolt"); 12 13 StormSubmitter.submitTopology( 14 "mytopology", 15 conf, 16 topologyBuilder.createTopology() 17 );
代碼如上,worker process,executor thread,task這些的數目均可以進行設置。
因此接下來咱們應該會關心一個topology默認對應的worker數是多少?一個executor默認對應的task數是多少?
更重要的是,咱們在編碼過程當中已經指定了worker process數和exector thread數,可是這兩個數能夠在運行時被修改,以更好地適應負載的變化!這樣的方式叫作rebalance!
它可以修改worker的數目,也就是說咱們是否能夠經過監控,來實現自動水平拓展呢??例如結合IaaS,加一個supervisor節點加入到集羣中?同時啓動對應的worker進程,當負載低的時候,收回對應的supervisor節點,將虛擬機返回到對應的VM池裏呢??
注意一點是:Task的數目在啓動後就不能變了,可是能夠改executor,即執行的線程數,因此executor數必定是小於等於task數,才能保證每個executor至少有一個task能夠運行.
因此對於task數太少,後期也沒法提升太多!
# 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
具體請參考wiki的文章