158
Twitter Storm Realtime distributed computations Sergey Lukjanov <[email protected] > Dmitry Mescheryakov <[email protected] > Wednesday, October 3, 12

Twitter Storm

Embed Size (px)

DESCRIPTION

Slides for internal techtalk about Twitter Storm

Citation preview

Page 1: Twitter Storm

Twitter StormRealtime distributed computations

Sergey Lukjanov <[email protected]>Dmitry Mescheryakov <[email protected]>

Wednesday, October 3, 12

Page 2: Twitter Storm

Real-time data processing

2Wednesday, October 3, 12

Page 3: Twitter Storm

Real-time data processingbefore Twitter Storm:

network of queues and workers

2Wednesday, October 3, 12

Page 4: Twitter Storm

Real-time data processingbefore Twitter Storm:

network of queues and workers

2

MESSAGES QUEUE

Wednesday, October 3, 12

Page 5: Twitter Storm

Real-time data processingbefore Twitter Storm:

network of queues and workers

2

MESSAGES QUEUE

Message routing can be

complex!

Wednesday, October 3, 12

Page 6: Twitter Storm

Real-time data processing

3

MESSAGES QUEUE

QUEUE

QUEUE

MESSAGES

MESSAGES

Wednesday, October 3, 12

Page 7: Twitter Storm

Real-time data processing

3

MESSAGES QUEUE

QUEUE

QUEUE

MESSAGES

MESSAGESQueues replication is needed for reliability

Wednesday, October 3, 12

Page 8: Twitter Storm

Real-time data processing

3

MESSAGES QUEUE

QUEUE

QUEUE

MESSAGES

MESSAGESQueues replication is needed for reliability

Hard to maintain queues

Wednesday, October 3, 12

Page 9: Twitter Storm

Real-time data processing

3

MESSAGES QUEUE

QUEUE

QUEUE

MESSAGES

MESSAGESQueues replication is needed for reliability

Hard to maintain queues

Each new computation branch

requires routing reconfiguration

Wednesday, October 3, 12

Page 10: Twitter Storm

Twitter Storm

4Wednesday, October 3, 12

Page 11: Twitter Storm

Twitter Stormdistributed;

4Wednesday, October 3, 12

Page 12: Twitter Storm

Twitter Stormdistributed;

fault-tolerant;

4Wednesday, October 3, 12

Page 13: Twitter Storm

Twitter Stormdistributed;

fault-tolerant;

real-time;

4Wednesday, October 3, 12

Page 14: Twitter Storm

Twitter Stormdistributed;

fault-tolerant;

real-time;

computation;

4Wednesday, October 3, 12

Page 15: Twitter Storm

Twitter Stormdistributed;

fault-tolerant;

real-time;

computation;

fail-fast components.

4Wednesday, October 3, 12

Page 16: Twitter Storm

(Very) basic info

5Wednesday, October 3, 12

Page 17: Twitter Storm

(Very) basic infocreated by Nathan Marz from Backtype/Twitter;

5Wednesday, October 3, 12

Page 18: Twitter Storm

(Very) basic infocreated by Nathan Marz from Backtype/Twitter;

Eclipse Public License 1.0;

5Wednesday, October 3, 12

Page 19: Twitter Storm

(Very) basic infocreated by Nathan Marz from Backtype/Twitter;

Eclipse Public License 1.0;

open sourced at September 19th, 2011;

5Wednesday, October 3, 12

Page 20: Twitter Storm

(Very) basic infocreated by Nathan Marz from Backtype/Twitter;

Eclipse Public License 1.0;

open sourced at September 19th, 2011;

about 16k Java and 7k Clojure LoC;

5Wednesday, October 3, 12

Page 21: Twitter Storm

(Very) basic infocreated by Nathan Marz from Backtype/Twitter;

Eclipse Public License 1.0;

open sourced at September 19th, 2011;

about 16k Java and 7k Clojure LoC;

most watched Java repo at Github (> 4k watchers);

5Wednesday, October 3, 12

Page 22: Twitter Storm

(Very) basic infocreated by Nathan Marz from Backtype/Twitter;

Eclipse Public License 1.0;

open sourced at September 19th, 2011;

about 16k Java and 7k Clojure LoC;

most watched Java repo at Github (> 4k watchers);

active UG.

5Wednesday, October 3, 12

Page 23: Twitter Storm

Current status

6Wednesday, October 3, 12

Page 24: Twitter Storm

Current statuscurrent stable release: 0.8.1;

6Wednesday, October 3, 12

Page 25: Twitter Storm

Current statuscurrent stable release: 0.8.1;

0.8.2 with small bug fixes is already on the way;

6Wednesday, October 3, 12

Page 26: Twitter Storm

Current statuscurrent stable release: 0.8.1;

0.8.2 with small bug fixes is already on the way;

0.9.0 with major core improvements is planned;

6Wednesday, October 3, 12

Page 27: Twitter Storm

Current statuscurrent stable release: 0.8.1;

0.8.2 with small bug fixes is already on the way;

0.9.0 with major core improvements is planned;

not very active contributions, we can try to get into;

6Wednesday, October 3, 12

Page 28: Twitter Storm

Current statuscurrent stable release: 0.8.1;

0.8.2 with small bug fixes is already on the way;

0.9.0 with major core improvements is planned;

not very active contributions, we can try to get into;

used by over 30 companies (such as Twitter, Groupon, Alibaba, GumGum, etc).

6Wednesday, October 3, 12

Page 29: Twitter Storm

Key properties

7Wednesday, October 3, 12

Page 30: Twitter Storm

Key propertiesextremely broad set of use cases:

streams processing;

database updating;

distributed rpc;

7Wednesday, October 3, 12

Page 31: Twitter Storm

Key propertiesextremely broad set of use cases:

streams processing;

database updating;

distributed rpc;

scalable and extremely robust;

7Wednesday, October 3, 12

Page 32: Twitter Storm

Key propertiesextremely broad set of use cases:

streams processing;

database updating;

distributed rpc;

scalable and extremely robust;

guarantees no data loss;

7Wednesday, October 3, 12

Page 33: Twitter Storm

Key propertiesextremely broad set of use cases:

streams processing;

database updating;

distributed rpc;

scalable and extremely robust;

guarantees no data loss;

fault-tolerant;

7Wednesday, October 3, 12

Page 34: Twitter Storm

Key propertiesextremely broad set of use cases:

streams processing;

database updating;

distributed rpc;

scalable and extremely robust;

guarantees no data loss;

fault-tolerant;

programming language agnostic.7

Wednesday, October 3, 12

Page 35: Twitter Storm

Key conceptsTuples (ordered list of elements)

8Wednesday, October 3, 12

Page 36: Twitter Storm

Key conceptsTuples (ordered list of elements)

8

( “Saratov”, “slukjanov”, “event1”, “10/3/12 16:20”)

Wednesday, October 3, 12

Page 37: Twitter Storm

Key conceptsStreams (unbounded sequence of tuples)

9Wednesday, October 3, 12

Page 38: Twitter Storm

Key conceptsStreams (unbounded sequence of tuples)

9

TUPLE TUPLE TUPLE TUPLE TUPLE

Wednesday, October 3, 12

Page 39: Twitter Storm

Key conceptsSpouts (source of streams)

10Wednesday, October 3, 12

Page 40: Twitter Storm

Key conceptsSpouts (source of streams)

10

TUPLE TUPLE TUPLE TUPLE TUPLE

Wednesday, October 3, 12

Page 41: Twitter Storm

Key conceptsSpouts (source of streams)

10

TUPLE TUPLE TUPLE TUPLE TUPLE

Spouts can talk with:queues;

logs;

API calls;

event data.

Wednesday, October 3, 12

Page 42: Twitter Storm

Key conceptsBolts (process tuples and create new streams)

11Wednesday, October 3, 12

Page 43: Twitter Storm

Key conceptsBolts (process tuples and create new streams)

11

TUPLE TUPLE TUPLE TUPLE TUPLE

TUPLETUPLE

TUPLETUPLE

TUPLE

TUPLE

TUPLE

TUPLE

TUPLE

TUPLE

Wednesday, October 3, 12

Page 44: Twitter Storm

Key conceptsYou can do the following things in Bolts:

12

apply functions / transformations;

filter;

aggregation;

streaming joins;

access DBs, APIs, etc...

Wednesday, October 3, 12

Page 45: Twitter Storm

Key conceptsTopologies (a directed graph of Spouts and Bolts)

13Wednesday, October 3, 12

Page 46: Twitter Storm

Key conceptsTopologies (a directed graph of Spouts and Bolts)

13

TUPLE TUPLE TUPLE TUPLE TUPLE

TUPLETUPLE

TUPLETUPLE

TUPL

TUPLE

TUPLE

TUPLE

TUPLE

TUPLE

Wednesday, October 3, 12

Page 47: Twitter Storm

Key conceptsTopologies (a directed graph of Spouts and Bolts)

14

TUPLE TUPLE TUPLE TUPLE TUPLE

TUPLE TUPLE TUPLE TUPLE TUPLE

TUPLE

TUPLE

TUPLE

TUPLE

TUPLE

TUPLE TUPLE TUPLE TUPLE TUPLE

TUPLE TUPLE TUPLE TUPLE TUPLE

TUPLE

TUPLE

TUPLE

TUPLE

TUPLE

Wednesday, October 3, 12

Page 48: Twitter Storm

Key conceptsTasks (instances of spouts and bolts)

15Wednesday, October 3, 12

Page 49: Twitter Storm

Key conceptsTasks (instances of spouts and bolts)

15

Task 1

Task 2

Task 3

Task 4

Wednesday, October 3, 12

Page 50: Twitter Storm

Key conceptsCluster

16

Nimbus

Zookeeper

Zookeeper

Zookeeper

Supervisor

Supervisor

Supervisor

Supervisor

Supervisor

Wednesday, October 3, 12

Page 51: Twitter Storm

Key conceptsCluster

16

Nimbus

Zookeeper

Zookeeper

Zookeeper

Supervisor

Supervisor

Supervisor

Supervisor

Supervisor

UI

Wednesday, October 3, 12

Page 52: Twitter Storm

Key conceptsCluster

16

Nimbus

Zookeeper

Zookeeper

Zookeeper

Supervisor

Supervisor

Supervisor

Supervisor

Supervisor

Hadoop’s Job tracker

UI

Wednesday, October 3, 12

Page 53: Twitter Storm

Key conceptsCluster

16

Nimbus

Zookeeper

Zookeeper

Zookeeper

Supervisor

Supervisor

Supervisor

Supervisor

Supervisor

Hadoop’s Job tracker

Hadoop’s Task tracker

UI

Wednesday, October 3, 12

Page 54: Twitter Storm

Based on

17Wednesday, October 3, 12

Page 55: Twitter Storm

Based onApache Zookeeper (maintaining configs);

17Wednesday, October 3, 12

Page 56: Twitter Storm

Based onApache Zookeeper (maintaining configs);

∅MQ (transport layer);

17Wednesday, October 3, 12

Page 57: Twitter Storm

Based onApache Zookeeper (maintaining configs);

∅MQ (transport layer);

Apache Thrift (cross-language bridge, rpc);

17Wednesday, October 3, 12

Page 58: Twitter Storm

Based onApache Zookeeper (maintaining configs);

∅MQ (transport layer);

Apache Thrift (cross-language bridge, rpc);

LMAX Disruptor (bounded prod-cons queue);

17Wednesday, October 3, 12

Page 59: Twitter Storm

Based onApache Zookeeper (maintaining configs);

∅MQ (transport layer);

Apache Thrift (cross-language bridge, rpc);

LMAX Disruptor (bounded prod-cons queue);

Kryo (serialization framework).

17Wednesday, October 3, 12

Page 60: Twitter Storm

Grouping

18Wednesday, October 3, 12

Page 61: Twitter Storm

Groupingshuffle (randomly and evenly distributed);

18Wednesday, October 3, 12

Page 62: Twitter Storm

Groupingshuffle (randomly and evenly distributed);

local or shuffle (local workers are preferred);

18Wednesday, October 3, 12

Page 63: Twitter Storm

Groupingshuffle (randomly and evenly distributed);

local or shuffle (local workers are preferred);

fields (the stream is partitioned by specified fields);

18Wednesday, October 3, 12

Page 64: Twitter Storm

Groupingshuffle (randomly and evenly distributed);

local or shuffle (local workers are preferred);

fields (the stream is partitioned by specified fields);

all (the stream is replicated across all the bolt’s tasks);

18Wednesday, October 3, 12

Page 65: Twitter Storm

Groupingshuffle (randomly and evenly distributed);

local or shuffle (local workers are preferred);

fields (the stream is partitioned by specified fields);

all (the stream is replicated across all the bolt’s tasks);

global (the entire stream goes to a single bolt’s task);

18Wednesday, October 3, 12

Page 66: Twitter Storm

Groupingshuffle (randomly and evenly distributed);

local or shuffle (local workers are preferred);

fields (the stream is partitioned by specified fields);

all (the stream is replicated across all the bolt’s tasks);

global (the entire stream goes to a single bolt’s task);

direct (producers could directly emit tuples);

18Wednesday, October 3, 12

Page 67: Twitter Storm

Groupingshuffle (randomly and evenly distributed);

local or shuffle (local workers are preferred);

fields (the stream is partitioned by specified fields);

all (the stream is replicated across all the bolt’s tasks);

global (the entire stream goes to a single bolt’s task);

direct (producers could directly emit tuples);

custom (implement interface CustomStreamGrouping).

18Wednesday, October 3, 12

Page 68: Twitter Storm

WordCount sample

19Wednesday, October 3, 12

Page 69: Twitter Storm

WordCount samplerandom sentence generator;

19Wednesday, October 3, 12

Page 70: Twitter Storm

WordCount samplerandom sentence generator;

sentence splitter;

19Wednesday, October 3, 12

Page 71: Twitter Storm

WordCount samplerandom sentence generator;

sentence splitter;

word counter;

19Wednesday, October 3, 12

Page 72: Twitter Storm

WordCount samplerandom sentence generator;

sentence splitter;

word counter;

ping spout (metronome).

19Wednesday, October 3, 12

Page 73: Twitter Storm

WordCount sample

20Wednesday, October 3, 12

Page 74: Twitter Storm

WordCount sample

20

SENTENCE SENTENCE

SENTENCE GENERATOR

Wednesday, October 3, 12

Page 75: Twitter Storm

WordCount sample

20

SENTENCE SENTENCE

SENTENCE GENERATOR

WORD WORD

SENTENCESPLITTER

Wednesday, October 3, 12

Page 76: Twitter Storm

WordCount sample

20

SENTENCE SENTENCE

SENTENCE GENERATOR

WORD WORD

SENTENCESPLITTER

WORDCOUNTER

Wednesday, October 3, 12

Page 77: Twitter Storm

WordCount sample

20

SENTENCE SENTENCE

SENTENCE GENERATOR

WORD WORD

SENTENCESPLITTER

WORDCOUNTER

GROUP BY WORD

Wednesday, October 3, 12

Page 78: Twitter Storm

WordCount sample

20

SENTENCE SENTENCE

SENTENCE GENERATOR

WORD WORD

SENTENCESPLITTER

WORDCOUNTER

PING

PINGPINGGENERATOR

GROUP BY WORD

Wednesday, October 3, 12

Page 79: Twitter Storm

WordCount sample

20

SOUT

SENTENCE SENTENCE

SENTENCE GENERATOR

WORD WORD

SENTENCESPLITTER

WORDCOUNTER

PING

PINGPINGGENERATOR

GROUP BY WORD

Wednesday, October 3, 12

Page 80: Twitter Storm

WordCount sample

20

SENTENCE SENTENCE

SENTENCE GENERATOR

WORD WORD

SENTENCESPLITTER

WORDCOUNTER

PING

PINGPINGGENERATOR

DB

GROUP BY WORD

Wednesday, October 3, 12

Page 81: Twitter Storm

Sentence generator

21

public class RandSentenceGenerator extends BaseRichSpout { private SpoutOutputCollector collector; private Random random; private String[] sentences; @Override public void open(Map map, TopologyContext ctx, SpoutOutputCollector collector) { this.collector = collector; this.random = new Random(); this.sentences = <sentences array>; } @Override public void nextTuple() { Utils.sleep(10); String sentence = sentences[random.nextInt(sentences.length)]; collector.emit(new Values(sentence)); }

@Override public void declareOutputFields(OutputFieldsDeclarer declarer) { declarer.declare(new Fields("sentence")); } }

Wednesday, October 3, 12

Page 82: Twitter Storm

Sentence splitter

22

public class SplitSentence extends BaseBasicBolt { @Override public void execute(Tuple tuple, BasicOutputCollector collector) { String sentence = tuple.getString(0); for (String word : sentence.split("\\s")) { collector.emit(new Values(word)); } } @Override public void declareOutputFields(OutputFieldsDeclarer declarer) { declarer.declare(new Fields("word")); } }

Wednesday, October 3, 12

Page 83: Twitter Storm

Word count

23

public class WordCount extends BaseBasicBolt { private HashMultiset<String> words = HashMultiset.create();

@Override public void prepare(Map conf, TopologyContext ctx) { super.prepare(conf, ctx); this.logger = Logger.getLogger(this.getClass()); this.name = ctx.getThisComponentId(); this.task = ctx.getThisTaskIndex(); }

@Override public void execute(Tuple tuple, BasicOutputCollector collector) { String source = tuple.getSourceComponent(); if ("split".equals(source)) { words.add(tuple.getString(0)); } else if ("ping".equals(source)) { logger.warn("RESULT " + name + ":" + task + " :: " + words); } }

@Override public void declareOutputFields(OutputFieldsDeclarer declarer) { declarer.declare(new Fields("word", "count")); } }

Wednesday, October 3, 12

Page 84: Twitter Storm

Topology builder

24

public class WordCounter { public static void main(String[] args) throws Exception { TopologyBuilder builder = new TopologyBuilder(); builder.setSpout("source", new RandSentenceGenerator(), 3); builder.setSpout("ping", new PingSpout()); builder.setBolt("split", new SplitSentence(), 8) .shuffleGrouping("source"); builder.setBolt("count", new WordCount(), 12) .fieldsGrouping("split", new Fields("word")) .allGrouping("ping");

<topology submitting> } }

Wednesday, October 3, 12

Page 85: Twitter Storm

Topology submitter

25

public class WordCounter { public static void main(String[] args) throws Exception { TopologyBuilder builder = new TopologyBuilder(); <building topology> Config conf = new Config(); conf.setDebug(true); conf.setNumWorkers(3); StormSubmitter.submitTopology("tplg-name", conf, builder.createTopology()); } }

Wednesday, October 3, 12

Page 86: Twitter Storm

Multilang support

26Wednesday, October 3, 12

Page 87: Twitter Storm

Multilang supportDSLs for Scala, JRuby and Clojure;

26Wednesday, October 3, 12

Page 88: Twitter Storm

Multilang supportDSLs for Scala, JRuby and Clojure;

ShellSpout, ShellBolt;

26Wednesday, October 3, 12

Page 89: Twitter Storm

Multilang supportDSLs for Scala, JRuby and Clojure;

ShellSpout, ShellBolt;

json-based protocol:

receive/emit tuples;

ack/fail tuples;

write to logs.

26Wednesday, October 3, 12

Page 90: Twitter Storm

Online logs processing

27Wednesday, October 3, 12

Page 91: Twitter Storm

Online logs processing

27

Application

Application

Application QUEUE

Twitter Storm Cluster

RABBITMQ

STORAGE CASSANDRA

Wednesday, October 3, 12

Page 92: Twitter Storm

Online logs processing

28Wednesday, October 3, 12

Page 93: Twitter Storm

Online logs processing

28

RABBITMQ

Wednesday, October 3, 12

Page 94: Twitter Storm

Online logs processing

28

RABBITMQ

QUEUECONSUMER

LOGMESSAGES

Wednesday, October 3, 12

Page 95: Twitter Storm

Online logs processing

28

MESSAGE MESSAGE

MESSAGEPARSERSHUFFLE GROUPING

RABBITMQ

QUEUECONSUMER

LOGMESSAGES

Wednesday, October 3, 12

Page 96: Twitter Storm

Online logs processing

28

MESSAGE MESSAGE

MESSAGEPARSERSHUFFLE GROUPING

EVENT EVENT

FIELDS GROUPINGEVENT

AGGREGATOR

RABBITMQ

QUEUECONSUMER

LOGMESSAGES

Wednesday, October 3, 12

Page 97: Twitter Storm

Online logs processing

28

MESSAGE MESSAGE

MESSAGEPARSERSHUFFLE GROUPING

EVENT EVENT

FIELDS GROUPINGEVENT

AGGREGATOR

CASSANDRA

REALTIMEINFO & STATS

RABBITMQ

QUEUECONSUMER

LOGMESSAGES

Wednesday, October 3, 12

Page 98: Twitter Storm

Storm fault-tolerance

29Wednesday, October 3, 12

Page 99: Twitter Storm

Storm fault-tolerance

29

Parts of Storm cluster:

Zookeeper nodes;

Nimbus (master) node;

Supervisor nodes.

Wednesday, October 3, 12

Page 100: Twitter Storm

Nimbus as a point of failure

30Wednesday, October 3, 12

Page 101: Twitter Storm

Nimbus as a point of failure

30

when Nimbus is down:

topologies continue to work;

tasks from failing nodes aren’t respawned;

can’t upload a new topology or rebalance an old one;

Wednesday, October 3, 12

Page 102: Twitter Storm

Nimbus as a point of failure

30

when Nimbus is down:

topologies continue to work;

tasks from failing nodes aren’t respawned;

can’t upload a new topology or rebalance an old one;

impossible to run Nimbus at another node:

either fix the failed node;

or create new and resubmit all topologies.

Wednesday, October 3, 12

Page 103: Twitter Storm

Tuple types

31

spout tuple - emitted from Spouts;

child tuple - emitted from Bolts, based on parent tuple(s) (child or spout ones).

Wednesday, October 3, 12

Page 104: Twitter Storm

Tuple types

31

spout tuple - emitted from Spouts;

child tuple - emitted from Bolts, based on parent tuple(s) (child or spout ones).

[“the cow jumped over the moon”]

[“the”]

[“cow”]

[“jumped”]

[“over”]

[“the”]

[“moon”]

[“the”, 1]

[“cow”, 1]

[“jumped”, 1]

[“over”, 1]

[“the”, 2]

[“moon”, 1]

Wednesday, October 3, 12

Page 105: Twitter Storm

Reliability API Guaranties

32

public class QueueConsumer extends BaseRichSpout {

...

@Override public void nextTuple() { Message msg = queueClient.popMessage(); collector.emit(msg.getPayload(), msg.getId()); }

@Override public void ack(Object msgId) { queueClient.ack(msgId); } @Override public void fail(Object msgId) { queueClient.fail(msgId); }

...

}

Wednesday, October 3, 12

Page 106: Twitter Storm

Tuple tree tracking

33Wednesday, October 3, 12

Page 107: Twitter Storm

Tuple tree tracking

33

spout tuple creation:

collector.emit(values, msgId);

Wednesday, October 3, 12

Page 108: Twitter Storm

Tuple tree tracking

33

spout tuple creation:

collector.emit(values, msgId);

child tuple creation:

collector.emit(parentTuples, values);

Wednesday, October 3, 12

Page 109: Twitter Storm

Tuple tree tracking

33

spout tuple creation:

collector.emit(values, msgId);

child tuple creation:

collector.emit(parentTuples, values);

tuple end of processing:

collector.ack(tuple);

Wednesday, October 3, 12

Page 110: Twitter Storm

Tuple tree tracking

33

spout tuple creation:

collector.emit(values, msgId);

child tuple creation:

collector.emit(parentTuples, values);

tuple end of processing:

collector.ack(tuple);

tuple failed to process:

collector.fail(tuple);

Wednesday, October 3, 12

Page 111: Twitter Storm

Disabling reliability API

34Wednesday, October 3, 12

Page 112: Twitter Storm

Disabling reliability API

34

globally:

Config.TOPOLOGY_ACKER_EXECUTORS = 0;

Wednesday, October 3, 12

Page 113: Twitter Storm

Disabling reliability API

34

globally:

Config.TOPOLOGY_ACKER_EXECUTORS = 0;

on topology level:

collector.emit(values, msgId);

Wednesday, October 3, 12

Page 114: Twitter Storm

Disabling reliability API

34

globally:

Config.TOPOLOGY_ACKER_EXECUTORS = 0;

on topology level:

collector.emit(values, msgId);

for a single tuple:

collector.emit(parentTuples, values);

Wednesday, October 3, 12

Page 115: Twitter Storm

Acker system impl

35

every tuple is assigned a random 64-bit ID

Wednesday, October 3, 12

Page 116: Twitter Storm

Acker system impl

35

every tuple is assigned a random 64-bit ID

Spout Bolt A Bolt B Bolt C[1] [2] [3]

Wednesday, October 3, 12

Page 117: Twitter Storm

Acker system impl

35

every tuple is assigned a random 64-bit ID

Spout Bolt A Bolt B Bolt C[1] [2] [3]

[1] emit

Wednesday, October 3, 12

Page 118: Twitter Storm

Acker system impl

35

every tuple is assigned a random 64-bit ID

Spout Bolt A Bolt B Bolt C[1] [2] [3]

[1] emit[2] emit

Wednesday, October 3, 12

Page 119: Twitter Storm

Acker system impl

35

every tuple is assigned a random 64-bit ID

Spout Bolt A Bolt B Bolt C[1] [2] [3]

[1] emit[2] emit[1] ack

Wednesday, October 3, 12

Page 120: Twitter Storm

Acker system impl

35

every tuple is assigned a random 64-bit ID

Spout Bolt A Bolt B Bolt C[1] [2] [3]

[1] emit[2] emit[1] ack[3] emit

Wednesday, October 3, 12

Page 121: Twitter Storm

Acker system impl

35

every tuple is assigned a random 64-bit ID

Spout Bolt A Bolt B Bolt C[1] [2] [3]

[1] emit[2] emit[1] ack[3] emit[2] ack

Wednesday, October 3, 12

Page 122: Twitter Storm

Acker system impl

35

every tuple is assigned a random 64-bit ID

Spout Bolt A Bolt B Bolt C[1] [2] [3]

[1] emit[2] emit[1] ack[3] emit[2] ack[3] ack

Wednesday, October 3, 12

Page 123: Twitter Storm

Acker - simplified algo

36Wednesday, October 3, 12

Page 124: Twitter Storm

Acker - simplified algo

36

tuple tree:

{ Spout tuple ID, set };

Wednesday, October 3, 12

Page 125: Twitter Storm

Acker - simplified algo

36

tuple tree:

{ Spout tuple ID, set };

message processing:

[tuple_id] emit: set.add(tuple_id);

[tuple_id] ack: set.remove(tuple_id);

if (set.size == 0): send ack to parent spout.

Wednesday, October 3, 12

Page 126: Twitter Storm

Acker - real algo

37

tuple tree:

{ Spout tuple ID, ackVal: int64 };

message processing:

[tuple_id] emit: ackVal ^= tuple_id;

[tuple_id] ack: ackVal ^= tuple_id;

if (ackVal == 0): send ack to parent spout.

Wednesday, October 3, 12

Page 127: Twitter Storm

Correctness of the tracking

38Wednesday, October 3, 12

Page 128: Twitter Storm

Correctness of the tracking

38

bolt fails before sending ack for a tuple:

no ack arrive before timeout, spout tuple fails;

Wednesday, October 3, 12

Page 129: Twitter Storm

Correctness of the tracking

38

bolt fails before sending ack for a tuple:

no ack arrive before timeout, spout tuple fails;

acker fails before acking tuple tree processing:

-- the same as above --;

Wednesday, October 3, 12

Page 130: Twitter Storm

Correctness of the tracking

38

bolt fails before sending ack for a tuple:

no ack arrive before timeout, spout tuple fails;

acker fails before acking tuple tree processing:

-- the same as above --;

spout fails before acking message:

the message source should handle client’s death.

Wednesday, October 3, 12

Page 131: Twitter Storm

Reliability API - Conclusion

39Wednesday, October 3, 12

Page 132: Twitter Storm

Reliability API - Conclusion

39

easy to dismiss:

on message - at most one processing;

Wednesday, October 3, 12

Page 133: Twitter Storm

Reliability API - Conclusion

39

easy to dismiss:

on message - at most one processing;

if using, little overhead and high durability:

one message - at least one processing;

Wednesday, October 3, 12

Page 134: Twitter Storm

Reliability API - Conclusion

39

easy to dismiss:

on message - at most one processing;

if using, little overhead and high durability:

one message - at least one processing;

with some further work (transactions, Trident API):

one message - exactly one processing.

Wednesday, October 3, 12

Page 135: Twitter Storm

Transactional approach: design #1

40Wednesday, October 3, 12

Page 136: Twitter Storm

Transactional approach: design #1

40

Spout Bolt ATUPLE COMMITMESSAGE

Wednesday, October 3, 12

Page 137: Twitter Storm

Transactional approach: design #1

40

input provides messages in strong order;

Spout Bolt ATUPLE COMMITMESSAGE

Wednesday, October 3, 12

Page 138: Twitter Storm

Transactional approach: design #1

40

input provides messages in strong order;

each message is assigned Transaction ID;

Spout Bolt ATUPLE COMMITMESSAGE

Wednesday, October 3, 12

Page 139: Twitter Storm

Transactional approach: design #1

40

input provides messages in strong order;

each message is assigned Transaction ID;

if (curr_tx_id > prev_tx_id) commit(result, curr_tx_id).

Spout Bolt ATUPLE COMMITMESSAGE

Wednesday, October 3, 12

Page 140: Twitter Storm

Transactional approach: design #2

41

input provides messages in strong order;

each batch of messages is assigned Transaction ID;

if (curr_tx_id > prev_tx_id) commit(result, curr_tx_id).

Spout Bolt A

BATCH OF TUPLES COMMIT

BATCH OFMESSAGES

Wednesday, October 3, 12

Page 141: Twitter Storm

Transactional approach: design #3

42

the same as #2, but each transaction is split:

processing phase;

commit phase;

Wednesday, October 3, 12

Page 142: Twitter Storm

Transactional approach: design #3

42

the same as #2, but each transaction is split:

processing phase;

commit phase;

process phases might intersect for difference transactions;

Wednesday, October 3, 12

Page 143: Twitter Storm

Transactional approach: design #3

42

the same as #2, but each transaction is split:

processing phase;

commit phase;

process phases might intersect for difference transactions;

commit phases go in strong order.

Wednesday, October 3, 12

Page 144: Twitter Storm

Trident API: Intro

43Wednesday, October 3, 12

Page 145: Twitter Storm

Trident API: Intro

43

high-level abstraction for doing realtime computations;

Wednesday, October 3, 12

Page 146: Twitter Storm

Trident API: Intro

43

high-level abstraction for doing realtime computations;

high throughput (millions of messages per second);

Wednesday, October 3, 12

Page 147: Twitter Storm

Trident API: Intro

43

high-level abstraction for doing realtime computations;

high throughput (millions of messages per second);

stateful stream processing;

Wednesday, October 3, 12

Page 148: Twitter Storm

Trident API: Intro

43

high-level abstraction for doing realtime computations;

high throughput (millions of messages per second);

stateful stream processing;

low latency distributed querying;

Wednesday, October 3, 12

Page 149: Twitter Storm

Trident API: Intro

43

high-level abstraction for doing realtime computations;

high throughput (millions of messages per second);

stateful stream processing;

low latency distributed querying;

different semantics (including exactly-once one);

Wednesday, October 3, 12

Page 150: Twitter Storm

Trident API: Intro

43

high-level abstraction for doing realtime computations;

high throughput (millions of messages per second);

stateful stream processing;

low latency distributed querying;

different semantics (including exactly-once one);

smth. like Pig or Cascading.

Wednesday, October 3, 12

Page 151: Twitter Storm

Trident API: Operations

44Wednesday, October 3, 12

Page 152: Twitter Storm

Trident API: Operations

44

partition-local operations (w/o network transfer):

function, filter, partitionAggregate, stateQuery, etc;

Wednesday, October 3, 12

Page 153: Twitter Storm

Trident API: Operations

44

partition-local operations (w/o network transfer):

function, filter, partitionAggregate, stateQuery, etc;

repartitioning operations (grouping);

Wednesday, October 3, 12

Page 154: Twitter Storm

Trident API: Operations

44

partition-local operations (w/o network transfer):

function, filter, partitionAggregate, stateQuery, etc;

repartitioning operations (grouping);

aggregations operations:

aggregate, persistentAggregate;

Wednesday, October 3, 12

Page 155: Twitter Storm

Trident API: Operations

44

partition-local operations (w/o network transfer):

function, filter, partitionAggregate, stateQuery, etc;

repartitioning operations (grouping);

aggregations operations:

aggregate, persistentAggregate;

operations on grouped streams;

Wednesday, October 3, 12

Page 156: Twitter Storm

Trident API: Operations

44

partition-local operations (w/o network transfer):

function, filter, partitionAggregate, stateQuery, etc;

repartitioning operations (grouping);

aggregations operations:

aggregate, persistentAggregate;

operations on grouped streams;

merges and joins.

Wednesday, October 3, 12

Page 157: Twitter Storm

Trident API: Demo

45

TridentTopology topology = new TridentTopology(); TridentState wordCounts = topology.newStream("spout1", new FixedBatchSpout()) .each(new Fields("sentence"), new Split(), new Fields("word")) .groupBy(new Fields("word")) .persistentAggregate(new MemoryMapState.Factory(), new Count(), new Fields("count")) .parallelismHint(6); topology.newDRPCStream("words") .each(new Fields("args"), new Split(), new Fields("word")) .groupBy(new Fields("word")) .stateQuery(wordCounts, new Fields("word"), new MapGet(), new Fields("count")) .each(new Fields("count"), new FilterNull()) .aggregate(new Fields("count"), new Sum(), new Fields("sum")); Config config = new Config(); config.setMaxSpoutPending(100); cluster.submitTopology("word-count-tplg", config, topology.build()); DRPCClient client = new DRPCClient("drpc.server.host", 3772); System.out.println(client.execute("words", "cat dog the man")); System.out.println(client.execute("words", "cat")); // prints the JSON-encoded result, e.g.: "[[5078]]"

Wednesday, October 3, 12

Page 158: Twitter Storm

Q & A

46Wednesday, October 3, 12