Twitter Storm source code analysis-CoordinatedBolt

Source: Internet
Author: User

The most frequently asked question about the new feature of Twitter Storm: Transactional Topology is: how does Storm know that a Bolt has completed all of its tuple processing? In fact, there are still a lot of things to do. Fortunately, Storm has provided a Bolt to help us do all these things. This awesome bolt is
CoordinatedBolt. What's important isCoordinatedBoltThe implementation is also based on the storm primitive spout and bolt-that is, we can implement it ourselves even if the author does not provide it. Let's take a look at the implementation principles of this class.

Although CoordinatedBolt plays a very powerful role, its principle is not very complicated. It is now used in two scenarios:

  • DRPC
  • Transactional Topology

ReadingCoordinatedBoltBefore proceeding, Let's first look at what is "handled" and what is handled?
In fact, CoordinatedBolt is not completely intrusive to the business. To use the features provided by CoordinatedBolt, you must ensure that the first field of each tuple sent by each bolt isrequest-idSo the so-called "done" means that the current bolt has finished the work required for the current "request-id. Thisrequest-idInDRPCIt represents a DRPC request, and a batch in Transactional Topology.

The principle of CoordinatedBolt is as follows:

  • Bolts in DRPC and Transactional Topology are encapsulated by CoordinatedBolt. That is to say, the bolts running in the Topology in DRPC and Transactional topology are not the original bolts provided by users, but a bunch of coordinatedbolts, coordinatedbolts, all these Bolt transactions are proxies.
  • With this proxy layer, CoordinatedBolt can do its work.
  • It maintains the following data on its own:
    • Which upstream tasks need to send me tuple? (You can obtain the grouping information provided when constructing the topology)
    • Which downstream tasks do I send tuple? (Also known through grouping information)
  • Each CoordinatedBolt records the task to which the tuple is sent after each real bolt sends a tuple.
  • After all its tuple has been sent (How do you know it has been sent? Wait a moment.) It uses another special stream to tell all tasks that it has sent tuple in emitDirect mode and how many tuple it has sent to it.
  • After a bolt receives the number of tuple messages from all upstream tasks, it compares the number of tuple messages it receives. If the number is correct, it receives all the tuple-it has completed processing.
  • In this way, the processing is complete. It can repeat the above steps to notify its downstream, and its downstream will then notify its downstream.
  • To sum up, how does each tuple know that the processing is complete? It depends on upstream notifications. So as long as a bolt has an upstream node, it can know when it will be finished.
  • There is always a bolt that has no upstream-the bolt at the top. So how does bolt know that it has been processed? It depends on the storm ack system-as long as it ack the tuple sent by its upstream (a non-CoordinatedBolt is PrepareRequest in the drpc), it will process the tuple. -That is to say, for the bolt at the top, it only needs to process one tuple (compared to its downstream, processing a lot of tuple is complete)

The specific principles are as follows:

As we talked about the concept of "completion" above,CoordinatedBoltThe use of is intrusive to the business: you must add the currentrequest-idOtherwiseCoordinatedBoltAnd cannot be tracked. A more elegant method is the IP address in the network protocol stack and the TCP protocol. The information required by the IP layer is included in the IP packet outside the TCP packet, but the information required by the IP layer is not required to be included in the TCP packet field, when sending data, the TCP layer only assembles the TCP fields and adds the information of the IP layer to the IP layer. The IP layer automatically removes the information on the IP layer before transmitting data packets to the TCP layer. TCP only displays the fields on its own layer without any intrusion .. The author puts forward some improvement measures for this question.

Recommended reading:

Twitter Storm installation configuration (cluster) Notes

Install a Twitter Storm Cluster

Notes on installing and configuring Twitter Storm (standalone version)

Storm practice and Example 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.