storm的並發

來源:互聯網
上載者:User
1 storm並行的基本概念
storm叢集中的一個機器可以運行一個或者多個worker,對應於一個或者多個topologies. 1個worker進程運行1個或多個excutor線程。每個worker從屬於一個topology. executor是單線程。每1個executor運行著相同的組件(spout或bolt)的1個或多個task。 1個task執行著實際的資料處理。 一個實際的例子:
What Description Configuration option How to set in your code (examples)
#worker processes How many worker processes to createfor the topologyacross machines in the cluster. Config#TOPOLOGY_WORKERS Config#setNumWorkers
#executors (threads) How many executors to spawnper component. ? TopologyBuilder#setSpout() and TopologyBuilder#setBolt()


Note that as of Storm 0.8 theparallelism_hint parameter now specifies the initial number of executors (not tasks!) for that bolt.
#tasks How many tasks to create per component. Config#TOPOLOGY_TASKS ComponentConfigurationDeclarer#setNumTasks()

Here is an example code snippet to show these settings in practice: Configuring the parallelism of a Storm bolt

123
topologyBuilder.setBolt("green-bolt", new GreenBolt(), 2)               .setNumTasks(4)               .shuffleGrouping("blue-spout");

In the above code we configured Storm to run the bolt GreenBolt with an initial number of two executors and four associated tasks. Storm will run two tasks per executor (thread). If you do not explicitly configure the number of tasks, Storm will run by default one task per executor.

詳細的參考:http://www.michael-noll.com/blog/2012/10/16/understanding-the-parallelism-of-a-storm-topology/


2  是否需要提高workers數目


(1)  最好 一台機器上的一個topology只使用一個worker,主要原因時減少了worker之間的資料轉送

How many Workers should I use?

The total number of workers is set by the supervisors – there’s some number of JVM slots each supervisor will superintend. The thing you set on the topology is how many worker slots it will try to claim.

There’s no great reason to use more than one worker per topology per machine.

With one topology running on three 8-core nodes, and parallelism hint 24, each bolt gets 8 executors per machine, i.e. one for each core. There are three big benefits to running three workers (with 8 assigned executors each) compare to running say 24 workers (one assigned executor each).

First, data that is repartitioned (shuffles or group-bys) to executors in the same worker will not have to hit the transfer buffer. Instead, tuples are deposited directly from send to receive buffer. That’s a big win. By contrast, if the destination executor were on the same machine in a different worker, it would have to go send -> worker transfer -> local socket -> worker recv -> exec recv buffer. It doesn’t hit the network card, but it’s not as big a win as when executors are in the same worker.

Second, you’re typically better off with three aggregators having very large backing cache than having twenty-four aggregators having small backing caches. This reduces the effect of skew, and improves LRU efficiency.

Lastly, fewer workers reduces control flow chatter.

(2)

Increasing the number of workers (responsible for running one or more executors for one or more components) might also gives you a performance benefit, but this also relative as I found from this discussion wherenathanmarz says

Having more workers might have better performance, depending on where your bottleneck is. Each worker has a single thread that passes tuples on to the 0mq connections for transfer to other workers, so if you're bottlenecked on CPU and each worker is dealing with lots of tuples, more workers will probably net you better throughput.

So basically there is no definite answer to this, you should try different configuration based on your environment and design. 3 executor的數目

executor是真正的並行度(事實上的並行度)。(task數目是想要設定的並行度)

executor初始數目=spout數目+bolt數目+acker數目 (這些加起來也就是task數目。)

spout數目,bolt數目,acker數目運行時是不會變化的,但是executor數目可以變化。 


4   是否需要提高TASK數目

TASK的存在只是為了topology擴充的靈活性,與並行度無關。

Disclaimer: I wrote the article you referenced in your question above.

However I'm a bit confused by the concept of "task". Is a task an running instance of the component(spout or bolt) ? A executor having multiple tasks actually is saying the same component is executed for multiple times by the executor, am I correct ?

Yes, and yes.

Moreover in a general parallelism sense, Storm will spawn a dedicated thread(executor) for a spout or bolt, but what is contributed to the parallelism by an executor(thread) having multiple tasks ?

Running more than one task per executor does not increase the level of parallelism -- an executor always has one thread that it uses for all of its tasks, which means that tasks run serially on an executor.

As I wrote in the article please note that: The number of executor threads can be changed after the topology has been started (seestorm rebalance command). The number of tasks of a topology is static.

And by definition there is the invariant of #executors <= #tasks.

So one reason for having 2+ tasks per executor thread is to give you the flexibility to expand/scale up the topology through thestorm rebalance command in the future without taking the topology offline. For instance, imagine you start out with a Storm cluster of 15 machines but already know that next week another 10 boxes will be added. Here you could opt for running the topology at the anticipated parallelism level of 25 machines already on the 15 initial boxes (which is of course slower than 25 boxes). Once the additional 10 boxes are integrated you can thenstorm rebalance the topology to make full use of all 25 boxes without any downtime.

Another reason to run 2+ tasks per executor is for (primarily functional) testing. For instance, if your dev machine or CI server is only powerful enough to run, say, 2 executors alongside all the other stuff running on the machine, you can still run 30 tasks (here: 15 per executor) to see whether code such as your custom Storm grouping is working as expected.

In practice we normally we run 1 task per executor.

PS: Note that Storm will actually spawn a few more threads behind the scenes. For instance, each executor has its own "send thread" that is responsible for handling outgoing tuples. There are also "system-level" background threads for e.g. acking tuples that run alongside "your" threads. IIRC the Storm UI counts those acking threads in addition to "your" threads. 轉自:http://stackoverflow.com/questions/17257448/what-is-the-task-in-twitter-storm-parallelism
一個運行中的拓撲是由什麼組成的:worker進程,executors和tasks。

Storm是按照下面3種主要的部分來區分Storm叢集中一個實際啟動並執行拓撲的: Worker進程 Executors (線程) Tasks

下圖簡單的展示了它們的關係:

 

 

上圖中的3段話依次如下: Storm叢集中的其中1台機器可能運行著屬於多個拓撲(可能為1個)的多個worker進程(可能為1個)。每個worker進程運行著特定的某個拓撲的executors。 1個或多個excutor可能運行於1個單獨的worker進程,每1個executor從屬於1個被worker process產生的線程中。每1個executor運行著相同的組件(spout或bolt)的1個或多個task。 1個task執行著實際的資料處理。

1個worker進程執行一個拓撲的子集。1個worker進程從屬於1個特定的拓撲,並運行著這個拓撲的1個或多個組件(spout或bolt)的1個或多個executor。一個運行中的拓撲包括叢集中的許多台機器上的許多個這樣的進程。

1個executor是1個worker進程產生的1個線程。它可能運行著1個相同的組件(spout或bolt)的1個或多個task。

1 個task執行著實際的資料處理,你用代碼實現的每一個spout或bolt就相當於分佈於整個叢集中的許多個task。在1個拓撲的生命週期中,1個組 件的task的數量總是一樣的,但是1個組件的executor(線程)的數量可以隨著時間而改變。這意味著下面的條件總是成立:thread的數量 <= task的數量。預設情況下,task的數量與executor的數量一樣,例如,Storm會在每1個線程運行1個task。 配置拓撲的並發度

注意Storm的術語"並發度(parallelism)"是特別用來描述所謂的parallelism hint的,這代表1個組件的初始的executor(線程)的數量。在此文檔中我們使用術語"並發度"的一般意義來描述你不但可以配置executor的數量,還可以配置worker進程的數量,還可以是1個拓撲的task的數量。在用到並發度的狹義的定義時我們會特別提出。

下面的小節給出了一些不同的配置選項,還有你如何在代碼中設定它們。有多種方法可以進行設定,表格列舉了其中幾種。Storm目前有下列的配置優先順序:defaults.yaml < storm.yaml < 特定拓撲的配置 < 內部特定組件的配置 < 外部特定組件的配置。

  worker進程的數量 描述: 1個拓撲有多少個分佈於叢集中的機器的worker進程 配置選項: TOPOLOGY_WORKERS 如何在代碼中設定 (例子): Config#setNumWorkers

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.