13
Apache Kafka 分散システムのツアー #3 Chris 2014/10/15 #m3dev https://github.com/m3dev/distrib-systems-tour

Tour of Distributed Systems 3 - Apache Kafka

Embed Size (px)

DESCRIPTION

分散システムのツアー #3 - Apache Kafka

Citation preview

Page 1: Tour of Distributed Systems 3 - Apache Kafka

Apache Kafka分散システムのツアー #3

Chris2014/10/15

#m3dev

https://github.com/m3dev/distrib-systems-tour

Page 2: Tour of Distributed Systems 3 - Apache Kafka

Kafka

● PubSubメッセージ・キュー● LinkedIn発● 売り

○ パフォーマンス○ スケーラビリティ○ 永続性○ 柔軟な配布モデル:コンシューマ・グループ

● Scala実装、多言語のクライアント

Page 3: Tour of Distributed Systems 3 - Apache Kafka

Consumer Group 2Consumer Group 1

アーキテクチャ

Producer Producer Producer Producer

Kafka cluster

Broker Broker Broker

Consumer Consumer Consumer Consumer

ZooKeeper

HDD HDD HDD

Page 4: Tour of Distributed Systems 3 - Apache Kafka

コンシューマ・グループ

● 全てのメッセージを全てのconsumer group(のconsumerのいずれか)に配布する

● 例)○ メッセージ 1, 2, 3, 4○ コンシューマグループ A, B○ Aにコンシューマ2台:A1, A2○ Bにコンシューマ2台:B1, B2

Group A Group B

A1 A2 B1 B2

①③ ②④ ①②③ ④

Page 5: Tour of Distributed Systems 3 - Apache Kafka

コンシューマ・グループ

● スペシャルケース○ 全てのコンシューマが同じグループに所属

■ 普通のキュー○ コンシューマはそれぞれ別グループ

■ 普通のPub-Sub

Page 6: Tour of Distributed Systems 3 - Apache Kafka

パーティション

● トピックを複数の partition に分ける● Producer が message ⇔ partition の振り分け

を決める● Kafka broker が partition ⇔ consumer の振り

分けを決める● 制限:Consumer数 ≦ Partition数

Producer

Producer

Partition 1

Partition 2

Consumer

Partition 3Consumer

(とある consumer group の中の話です)

Page 7: Tour of Distributed Systems 3 - Apache Kafka

永続性

● Brokerはメッセージをファイルに書き込む● Consumerがメッセージを消費しても、一定期間

brokerに残る● Consumerが自身の経過を管理するので、巻き

戻して再読み込みができる

Page 8: Tour of Distributed Systems 3 - Apache Kafka

パフォーマンス

結果:49,568 messages/sec (Late 2011 MBP, 100 byte msgs)

$ brew install kafka$ cd /usr/local/opt/kafka$ bin/start-zookeeper-server.sh libexec/config/zookeeper.properties &$ bin/kafka-server-start.sh libexec/config/server.properties &$ bin/kafka-topics.sh --create --zookeeper localhost:2181 \ --replication-factor 1 --partitions 1 \ --topic test$ bin/kafka-producer-perf-test.sh --broker-list localhost:9092 \ --topics test --messages 1000000

Page 9: Tour of Distributed Systems 3 - Apache Kafka

スケーラビリティ

LinkedIn社で1千億メッセージ/日!https://twitter.com/jaykreps/status/479749975853641729

Page 10: Tour of Distributed Systems 3 - Apache Kafka

使い所:リアルタイム通知

Page 11: Tour of Distributed Systems 3 - Apache Kafka

使い所:レポーティング

Page 12: Tour of Distributed Systems 3 - Apache Kafka

使い所:多目的イベント活用

Page 13: Tour of Distributed Systems 3 - Apache Kafka

ハンズオン!

OSX: brew install kafka

or, AWS上に稼働中のKafka を使う

192.168.51.119:9092

https://github.com/m3dev/distrib-systems-tour