Slide 1

Slide 1 text

Mackerel を支える - Redis の技術 - 株式会社はてな Webオペレーションエンジニア 大野一樹 (id:kizkoh) LINE Developer Meetup #36 - Redis - 1

Slide 2

Slide 2 text

About Me ● 大野 一樹 (@kizkoh / id:kizkoh) ● 株式会社はてな Web オペレーションエンジニア ● mackerel.io のサービス設計、運用をメインで担当 ● 最近の活動: K8S オペレーション、 コンテナ 2

Slide 3

Slide 3 text

Agenda ● Microservices コンポーネントを支える Redis 事例 ● 時系列データベースを支える Redis Cluster 事例 ● Redis, Redis Cluster の監視、モニタリング ● Redis 活用の次の一歩 3

Slide 4

Slide 4 text

https://mackerel.io 4

Slide 5

Slide 5 text

5

Slide 6

Slide 6 text

About Mackerel ● サーバモニタリング、監視のための SaaS ● サーバにあるエージェントからメトリックを投稿 ● mackerel.io でのグラフ閲覧、1 分粒度 ● zabbix, ganglia, prometheus のようなサービス 6

Slide 7

Slide 7 text

Mackerel を支える 3 つの Redis 7

Slide 8

Slide 8 text

Three Redis in Mackerel 8 Redis Session Store Database Cache 2 Nodes Redis Message Queue 3 Nodes Redis Cluster Time Series Database 3 Nodes x 13 Shards

Slide 9

Slide 9 text

Three Redis in Mackerel 9 Redis Session Store Database Cache 2 Nodes Redis Message Queue 3 Nodes Redis Cluster Time Series Database 3 Nodes x 13 Shards

Slide 10

Slide 10 text

メッセージキューとしての Redis 事例 10

Slide 11

Slide 11 text

Message Queue in Mackerel ● Message Queue Pub/Sub Model (Not Rescue) ○ HTTP 経由でメッセージング (Microservices) ○ 外形監視、 {AWS, Azure}インテグレーション 11 HTTP Requests Publish Job Subscribe Job

Slide 12

Slide 12 text

Message Queue in Mackerel ● 独自の Pub/Sub モデル (リスト型オブジェクト) ○ 数分間ごとに実行されるメッセージキュー 12 HTTP Requests Publish Job Subscribe Job

Slide 13

Slide 13 text

Redis HA (High Availability) in Mackerel ● Redis Sentinel を使わないレプリケーション ○ keepalived + Route Table + swiro hatena/swiro: swiro - A switching route tool for AWS 13 keepalived (master) keepalived (backup) Replication AWS VPC Route table

Slide 14

Slide 14 text

時系列データベースを支える Redis Cluster 事例 14

Slide 15

Slide 15 text

Key Factor of Time Series Database(TSDB) ● メトリックを時系列に保存するための DB, KVS ○ Key: metric name + time, Value: metric value 15

Slide 16

Slide 16 text

Time Series Database (TSDB) in Mackerel 16 Writer Endpoint Reader Endpoint Redis Cluster DynamoDB S3 Lambda Lambda (Trigger by TTL expire) Kinesis Streams

Slide 17

Slide 17 text

Service Dashboard in mackerel.io 17

Slide 18

Slide 18 text

Redis Cluster is Cache for TSDB ● Redis Cluster は時系列データベースのキャッシュ ● データアクセス頻度 vs コストモデル 18 High Cost 50 GB Medium Cost 500 GB Low Cost 2 TB

Slide 19

Slide 19 text

Redis Cluster Workload ● 時系列データベースのワークロード ○ Cluster: single cluster, 13 Shard, 39 Node ○ 60min, 6hour, 1week, 1month, 1 year のデータ ■ 1 粒度だけど粒度は丸められている ■ 同じホストメトリックは同じシャードに配置 ○ 1 分点、書き込み中心のワークロード ■ Write Heavy Workload 19

Slide 20

Slide 20 text

Redis Cluster の運用 20

Slide 21

Slide 21 text

Why We don’t use Elasticache Cluster? ● Redis Cluster on EC2 ○ Elasticache で作成できる上限は 15 シャード ○ インスタンスタイプの微調整ができない ○ トラブルが起こったときにわかりづらい ■ パケットキャプチャ、トラフィック解析 ■ Lambda, Redis Cluster 間のトラブルシュート 21

Slide 22

Slide 22 text

● chef を使って EC2 上に Redis Cluster を構築 ○ 社内は chef がプロビジョニングのスタンダード ○ エージェントをインストール、メトリック取得 ○ 1 ホスト複数 redis-server プロセス同居 ● クラスターへのジョインは自作ツールを利用 ○ ノード ID を意識しないオペレーション Redis Cluster の運用とモニタリング/監視のコツ – Itsuki – Medium Redis Cluster on EC2 22

Slide 23

Slide 23 text

Bottleneck of Redis Cluster ● 書き込み Heavy ○ メトリックが増えるとメモリがあふれる ○ CPU がボトルネック ■ Redis のシングルスレッド性能頭打ち ■ 書き込みエラーになると Lambda が詰まる 過剰なメトリック投稿 >> 過剰読み取りアクセス 23

Slide 24

Slide 24 text

Bottleneck of Redis Cluster ● 書き込み Heavy ○ Redis への書き込みが詰まる時 ■ Redis の CPU が限界値、 Full Resync 問題 ■ Lambda でエラーが発生する ○ Kinesis での Lambda Function のエラー処理 ■ 自動的にリトライ処理がされる ■ Redis への書き込みがされるまでリトライ => 書き込み失敗によるデータロストは発生しない 24

Slide 25

Slide 25 text

Retransmit of Metrics ● メトリックの再送 ○ サービスがダウン(メンテナンス)していた場合 ■ エージェントがメトリックをバッファ(保留) ■ エージェントがメトリックを再送 25 mackerel.io

Slide 26

Slide 26 text

Retransmit of Metrics ● メトリックの再送 ○ メトリックの再送が完了するまでの間 ■ メトリック投稿が 1.5 倍になる ■ Redis Cluster への書き込みが増加する 26 mackerel.io

Slide 27

Slide 27 text

Retransmit of Metrics ● メトリックの再送時の Redis Cluster CPU 27

Slide 28

Slide 28 text

Efforts to Reduce CPU Load ● CPU 負荷を抑えるための Redis Lua ○ メトリック書き込み負荷,、読み込み負荷が高い ○ Redis Lua で同じホストのメトリックを操作 ■ 同じホストの複数メトリックを Redis Lua で処理 28 HMSET KEY [FIELD VALUE ...] EVAL(MultiHmSet)

Slide 29

Slide 29 text

Mackerel を使った Redis の監視 29

Slide 30

Slide 30 text

Monitor Redis Metrics on mackerel.io ● mackerel-plugin-redis を使うと取得できる ○ INFO コマンドで取得できるメトリックを可視化 30

Slide 31

Slide 31 text

Replication Monitor on mackerel.io ● mackerel-plugin-redis でのレプリケーション監視 ○ slave{x}_offset_delay を可視化 31

Slide 32

Slide 32 text

Redis 活用の次の一歩 32

Slide 33

Slide 33 text

Next Steps for Redis in Mackerel ● CloudNative & Managed Service ○ Message Queue ■ nats.io, SQS, Redis on K8S ○ Redis Cluster ■ Elasticache Cluster, DynamoDB DAX ○ Redis 5.0 ?? 33

Slide 34

Slide 34 text

まとめ 34

Slide 35

Slide 35 text

Conclusion ● Mackerel の Redis 事例 ○ Message Queue & Redis Cluster ● Redis Monitoring on mackerel.io ● Redis for CloudNative era. 35

Slide 36

Slide 36 text

AWS Summit Tokyo にも出展中です!! 36