main components
-
nodes - machines
-
workers - jvms
-
executors - threads
-
tasks - bolt/spout instance
topology execution
-
config workers
-
1
sentence spout1
split bolt1
count bolt1
report boltConfig config = new Config(); config.setNumWorkers(2); builder.setSpout(SENTENCE_SPOUT_ID, spout); builder.setBolt(SPLIT_BOLT_ID, splitBolt); builder.setBolt(COUNT_BOLT_ID, countBolt) .fieldGrouping(SPLIT_BOLT_ID, new Fields("word"); builder.setBolt(REPORT_BOLT_ID, reportBolt) .globalGrouping(COUNT_BOLT_ID);
-
using
1
worker+-----------------------------------------------------------------+ | node | | +-------------------------------------------------------------+ | | | worker (JVM) | | | | +------------+ +------------+ +------------+ +------------+ | | | | | executor | | executor | | executor | | executor | | | | | | (thread) | | (thread) | | (thread) | | (thread) | | | | | | +--------+ | | -------- | | -------- | | -------- | | | | | | | task | | | / task \ | | / task \ | | / task \ | | | | | | | spout | | | | bolt | | | | bolt | | | | bolt | | | | | | | | | | | | | | | | | | | | | | | | | | | |sentence| | | |sentence| | | | word | | | | report | | | | | | | | | | | \ split / | | \ count / | | \ / | | | | | | +--------+ | | -------- | | -------- | | -------- | | | | | +------------+ +------------+ +------------+ +------------+ | | | +-------------------------------------------------------------+ | +-----------------------------------------------------------------+
-
adding workers to a topology
-
config workers
-
code
Config config = new Config(); config.setNumWorkers(2);
-
-
config executors and tasks
-
code
builder.setSpout(SENTENCE_SPOUT_ID, spout, 2);
-
using
one worker
+-----------------------------------------------------------------+ | node | | +-------------------------------------------------------------+ | | | worker (JVM) | | | | +------------+ +------------+ +------------+ +------------+ | | | | | executor | | executor | | executor | | executor | | | | | | (thread) | | (thread) | | (thread) | | (thread) | | | | | | +--------+ | | -------- | | -------- | | -------- | | | | | | | task | | | / task \ | | / task \ | | / task \ | | | | | | | spout | |>| | bolt | |>| | bolt | |>| | bolt | | | | | | | | | | | | | | | | | | | | | | | | | | | |sentence| | | |sentence| | | | word | | | | report | | | | | | | | | | | \ split / | | \ count / | | \ / | | | | | | +--------+ | | -------- | | -------- | | -------- | | | | | +------------+ +------------+ +------------+ +------------+ | | | | +------------+ ^ | | | | | executor | | | | | | | (thread) | | | | | | | +--------+ | | | | | | | | task | | | | | | | | | spout | |-------- | | | | | | | | | | | | | |sentence| | | | | | | | | | | | | | | +--------+ | | | | | +------------+ | | | +-------------------------------------------------------------+ | +-----------------------------------------------------------------+
-
-
setup split sentence bolt and word count bolt
-
split sentence bolt
execute as4 tasks
with2 executors
builder.setBolt(SPLIT_BOLT_ID, splitBolt, 2) .setNumTask(4) .shuffleGrouping(SENTENCE_SPOUT_ID);
-
word count bolt
execute as4 tasks
each with its own executor threadbuilder.setBolt(COUNT_BOLT_ID, countBolt, 4) .fieldGrouping(SPLIT_BOLT_ID, new Fields("word"));
-
using
2 workers
+-----------------------------------------------------------------+ | node | | +-------------------------------------------------------------+ | | | worker (JVM) | | | | +------------+ +------------+ +------------+ +------------+ | | | | | executor | | executor | | executor | | executor | | | | | | (thread) | | (thread) | | (thread) | | (thread) | | | | | | +--------+ | | -------- | | -------- | | -------- | | | | | | | task | | | / task \ | | / task \ | | / task \ | | | | | | | spout | | | | bolt | | | | bolt | | | | bolt | | | | | | | | | | | | | | | | | | | | | | | | | | | |sentence| | | |sentence| | | | word | | | | report | | | | | | | | | | | \ split / | | \ count / | | \ / | | | | | | +--------+ | | -------- | | -------- | | -------- | | | | | +------------+ | -------- | +------------+ +------------+ | | | | | / task \ | +------------+ | | | | | | bolt | | | executor | | | | | | | | | | (thread) | | | | | | |sentence| | | -------- | | | | | | \ split / | | / task \ | | | | | | -------- | | | bolt | | | | | | +------------+ | | | | | | | | | | word | | | | | | | \ count / | | | | | | -------- | | | | | +------------+ | | | +-------------------------------------------------------------+ | | +-------------------------------------------------------------+ | | | worker (JVM) | | | | +------------+ +------------+ +------------+ +------------+ | | | | | executor | | executor | | executor | | executor | | | | | | (thread) | | (thread) | | (thread) | | (thread) | | | | | | +--------+ | | -------- | | -------- | | -------- | | | | | | | task | | | / task \ | | / task \ | | / task \ | | | | | | | spout | | | | bolt | | | | bolt | | | | bolt | | | | | | | | | | | | | | | | | | | | | | | | | | | |sentence| | | |sentence| | | | word | | | | report | | | | | | | | | | | \ split / | | \ count / | | \ / | | | | | | +--------+ | | -------- | | -------- | | -------- | | | | | +------------+ | -------- | +------------+ +------------+ | | | | | / task \ | +------------+ | | | | | | bolt | | | executor | | | | | | | | | | (thread) | | | | | | |sentence| | | -------- | | | | | | \ split / | | / task \ | | | | | | -------- | | | bolt | | | | | | +------------+ | | | | | | | | | | word | | | | | | | \ count / | | | | | | -------- | | | | | +------------+ | | | +-------------------------------------------------------------+ | +-----------------------------------------------------------------+
-