How does emit () and multiple tick sets act in a storm?
I have a topology and run it in local mode like Spout A
---> Bolt B
---> Bolt C
. Moreover, I am defining an object Object D
which is the value emitted from B to C. I have two questions:
- I installed
TOPOLOGY_TICK_TUPLE_FREQ_SECS
inBolt B
and newObject D
whenBolt B
created. WhenTupleHelpers.isTickTuple(input)
true
, it emitsObject D
inBolt C
. I think the storm will cloneObject D
and generate a new one inBolt C
, however when I try to update the contentObject D
it still changes toBolt B
. What for? These two bolts can be on different servers and it is not possible to combine the same variables in memory between multiple bolts.
Bolt B
private final UserPreferBean userPrefer;
public FirstBolt() {
this.keyword = "Default";
this.userPrefer = new UserPreferBean();
this.userPrefer.setAction("Action");
this.userPrefer.setActor("Actor");
}
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
if (TupleHelpers.isTickTuple(input)) {
System.out.println("FirstBolt.Tick.keyword= " + userPrefer.getAction());
collector.emit(new Values(userPrefer));
} else {
}
}
Bolt C
@Override
public void execute(Tuple input, BasicOutputCollector collector) {
UserPreferBean userPrefer = (UserPreferBean) input.getValue(0);
System.out.println("SecondBolt.keyword= " + userPrefer.getAction());
userPrefer.setAction("NewAction");
System.out.println("SecondBolt.new.keyword= " + userPrefer.getAction());
}
- How does the storm work when I installed
TOPOLOGY_TICK_TUPLE_FREQ_SECS
inBolt B
andBolt C
. SinceBolt C
afterBolt B
, is it pointless to installTOPOLOGY_TICK_TUPLE_FREQ_SECS
in several bolts?
source to share
For your first question, you must update the new Tuple data for each emit, as there is no guarantee that this data will be serialized for transport before you want to emit another tuple. You may end up chafing all previously released but uncommitted tuples if you don't. As for bolt C getting the same object that bolt B fired, I guess this is just an effect trick Storm uses when two bolts are in the same JVM. Obviously you won't get this if the two objects are on different machines. This is another reason for the appearance of new objects.
For your second question, the TOPOLOGY_TICK_TUPLE_FREQ_SECS configuration is used to send extra tick sets to your bolt - above any other tuples that are sent to the bolt using the side bolts. This means that you can send tick-tuples to any number of components, as long as it makes sense for your topology design.
source to share
Tick tuple is an additional tuple that will be automatically generated by the storm at the configured frequency time interval. If you want to release an object D from Bolt B to Bolt C when you receive a tick set, there is no need to set up a tick set in Bolt C. In your example, you have set:
TOPOLOGY_TICK_TUPLE_FREQ_SECS=10
In Bolt B. Thus, Bolt B will receive a tick-tuple every 10 seconds, and during this time you can create an object D in Bolt B and emit an object in Bolt C, and Bolt C will complete the task and select a tuple.
source to share