Storm fields grouping

前端 未结 2 1359
-上瘾入骨i
-上瘾入骨i 2020-12-21 08:59

I\'m having the following situation:

  • There is a number of bolts that calculate different values
  • This values are sent to visualization bolt
  • Vi
相关标签:
2条回答
  • 2020-12-21 09:44

    I guess you can use Partial Key grouping (partialKeyGrouping). On the Storm documentation about stream groups says:

    Partial Key grouping: The stream is partitioned by the fields specified in the grouping, like the Fields grouping, but are load balanced between two downstream bolts, which provides better utilization of resources when the incoming data is skewed. This paper provides a good explanation of how it works and the advantages it provides.

    I implemented a simple topology using this grouping and the chart on Graphite server show a better load balance compared to fieldsGrouping. The full source code is here.

    topologyBuilder.setBolt(MqttSensors.BOLT_SENSOR_TYPE.getValue(), new SensorAggregateValuesWindowBolt().withTumblingWindow(Duration.seconds(5)), 2)
            // .fieldsGrouping(MqttSensors.SPOUT_STATION_01.getValue(), new Fields(MqttSensors.FIELD_SENSOR_TYPE.getValue()))
            // .fieldsGrouping(MqttSensors.SPOUT_STATION_02.getValue(), new Fields(MqttSensors.FIELD_SENSOR_TYPE.getValue()))
            .partialKeyGrouping(MqttSensors.SPOUT_STATION_01.getValue(), new Fields(MqttSensors.FIELD_SENSOR_TYPE.getValue()))
            .partialKeyGrouping(MqttSensors.SPOUT_STATION_02.getValue(), new Fields(MqttSensors.FIELD_SENSOR_TYPE.getValue()))
            .setNumTasks(4) // This will create 4 Bolt instances 
            .addConfiguration(TagSite.SITE.getValue(), TagSite.EDGE.getValue())
            ;
    

    0 讨论(0)
  • 2020-12-21 09:56

    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.

    0 讨论(0)
提交回复
热议问题