Reputation: 3832
I have a topology and run it in local mode, such like Spout A
---> Bolt B
---> Bolt C
. Moreover, I define an object Object D
, which is the value emitted from B to C. I have two questions:
TOPOLOGY_TICK_TUPLE_FREQ_SECS
in Bolt B
and new Object D
when Bolt B
is created. When TupleHelpers.isTickTuple(input)
is true
, it emit Object D
to Bolt C
. I think the storm will clone the Object D
and generate a new one in Bolt C
, however, when I try to update the content of Object D
, it still change in Bolt B
. Why? These two bolts may in different servers, and it is impossible share same variables in memory between multiple bolts.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 {
}
}
@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());
}
TOPOLOGY_TICK_TUPLE_FREQ_SECS
in Bolt B
and Bolt C
. Since bolt C
is after Bolt B
, is it meaningless to set TOPOLOGY_TICK_TUPLE_FREQ_SECS
in multiple bolt?Upvotes: 3
Views: 2101
Reputation: 39
Tick tuple is the additional tuple which will be automatically generated by a storm at configured frequency time interval. If you want to emit Object D from Bolt B to Bolt C when you receive tick tuple, there is no need to configure tick tuple in Bolt C. In your example, you have set:
TOPOLOGY_TICK_TUPLE_FREQ_SECS=10
In Bolt B. So Bolt B will receive a tick tuple every 10 second, and in that time you can create Object D in Bolt B and emit the object to Bolt C and the Bolt C will complete the task and ack the tuple.
Upvotes: 0
Reputation: 16392
For your first question, you should be new-ing up new Tuple data for each emit since there's no guarantee that that data will be serialized for transport before you want to emit another tuple. You could end up stamping all over previously emitted but uncommitted tuples if you don't. As for bolt C getting the same object as was emitted by bolt B, I'm guessing that that's just a performance trick Storm uses when the two bolts are in the same JVM. You obviously won't get that if the two objects are on different machines. That's another reason to new up objects to be emitted.
For your second question, the TOPOLOGY_TICK_TUPLE_FREQ_SECS config is used to send additional tick tuples to your bolt - above and beyond any other tuples that are sent to the bolt via upstream bolts. That means that you can send tick tuples to any number of components, just as long as it makes sense to your topology's design.
Upvotes: 1