风暴场分组 [英] Storm fields grouping
问题描述
我遇到以下情况:
- 有许多螺栓可以计算出不同的值
- 此值发送到可视化螺栓
- 可视化螺栓打开Web套接字并以某种方式发送要可视化的值
问题是,可视化螺栓始终是相同的,但是它会为每种类型的螺栓(其输入)发送带有不同标头的消息.例如:
- BoltSum计算总和
- BoltDif计算差异
-
BoltMul计算多个
-
所有这些螺栓都使用VisualizationBolt进行可视化
- 在这种情况下,有3个VisualizationBolt实例
我的问题是,我应该创建3个独立的实例,其中每个实例都有一个线程,例如
builder.setBolt("forSum", new VisualizationBolt(),1).globalGrouping("bolt-sum");
builder.setBolt("forDif", new VisualizationBolt(),1).globalGrouping("bolt-dif");
builder.setBolt("forMul", new VisualizationBolt(),1).globalGrouping("bolt-mul");
还是应该执行以下操作
builder.setBolt("forAll", new VisualizationBolt(),3)
.fieldsGrouping("forSum", new Fields("type"))
.fieldsGrouping("forDif", new Fields("type"))
.fieldsGrouping("forMul", new Fields("type"));
并从每个先前的螺栓中发出类型,以便可以基于它们进行分组?
有什么优势?
此外,我是否应该期望每次螺栓总和都将到达第一个可视化螺栓,bolt-dif将到达第二个可视化螺栓,bolt-mul将会到达第三个可视化螺栓?他们不会混在一起吗?
我认为应该是这种情况,但是目前不在我的实现中,所以我不确定这是一个错误还是缺少某些东西?
使用三个实例的第一种方法是正确的方法.使用fieldsGrouping
不能不确保"sum"值进入"Sum-Visualization-Bolt",并且sum/diff/mul值也不是唯一的(即,在不同的螺栓实例中)./p>
fieldGrouping
的语义更加宽松:它仅保证,同一类型的所有元组将由单个螺栓实例处理,即永远不会这样,两个不同的螺栓实例将获得相同类型.
I'm having the following situation:
- There is a number of bolts that calculate different values
- This values are sent to visualization bolt
- Visualization bolt opens a web socket and sends values to be visualized somehow
The thing is, visualization bolt is always the same, but it sends a message with a different header for each type of bolt that can be its input. For example:
- BoltSum calculates sum
- BoltDif calculates difference
BoltMul calculates multiple
All this bolts use VisualizationBolt for visualization
- There are 3 instances of VisualizationBolt in this case
My question is, should I create 3 independent instances, where each instance will have one thread, e.g.
builder.setBolt("forSum", new VisualizationBolt(),1).globalGrouping("bolt-sum");
builder.setBolt("forDif", new VisualizationBolt(),1).globalGrouping("bolt-dif");
builder.setBolt("forMul", new VisualizationBolt(),1).globalGrouping("bolt-mul");
Or should I do the following
builder.setBolt("forAll", new VisualizationBolt(),3)
.fieldsGrouping("forSum", new Fields("type"))
.fieldsGrouping("forDif", new Fields("type"))
.fieldsGrouping("forMul", new Fields("type"));
And emit type from each of the previous bolts, so they can be grouped on based on it?
What are the advantages?
Also, should I expect that each and every time bolt-sum will go to first visualization bolt, bolt-dif will go to second visualization bolt and bolt-mul will go to third visualization bolt? They won't be mixed?
I think that that should be the case, but it currently isn't in my implementation, so I'm not sure if it's a bug or I'm missing something?
The first approach using three instances is the correct approach. Using fieldsGrouping
does not ensure, that "sum" values go to "Sum-Visualization-Bolt" and neither that sum/diff/mul values are distinct (ie, in different bolt instances).
The semantic of fieldGrouping
is more relaxed: it only guarantees, that all tuples of the same type will be processed by a single bolt instance, ie, that it will never be the case, that two different bolt instances get the same type.
这篇关于风暴场分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!