Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
スケーラビリティのためのSansanアプリケーション基盤
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Junya Wada
July 28, 2016
Technology
2
650
スケーラビリティのためのSansanアプリケーション基盤
Sansan×gloops インフラ合同勉強会
http://connpass.com/event/33442/
Junya Wada
July 28, 2016
Tweet
Share
Other Decks in Technology
See All in Technology
SLI/SLO 導入で 避けるべきこと3選
yagikota
0
140
ソフトバンク流!プラットフォームエンジニアリング実現へのアプローチ
sbtechnight
1
240
モジュラモノリス導入から4年間の総括:アーキテクチャと組織の相互作用について / Architecture and Organizational Interaction
nazonohito51
3
1.3k
_Architecture_Modernization_から学ぶ現状理解から設計への道のり.pdf
satohjohn
2
630
OpenClaw を Amazon Lightsail で動かす理由
uechishingo
0
250
コンテキスト・ハーネスエンジニアリングの現在
hirosatogamo
PRO
6
690
AIエージェント×GitHubで実現するQAナレッジの資産化と業務活用 / QA Knowledge as Assets with AI Agents & GitHub
tknw_hitsuji
0
140
Phase08_クイックウィン実装
overflowinc
0
660
頼れる Agentic AI を支える Datadog のオブザーバビリティ / Powering Reliable Agentic AI with Datadog Observability
aoto
PRO
0
250
CyberAgentの生成AI戦略 〜変わるものと変わらないもの〜
katayan
0
280
スピンアウト講座02_ファイル管理
overflowinc
0
490
形式手法特論:SMT ソルバで解く認可ポリシの静的解析 #kernelvm / Kernel VM Study Tsukuba No3
ytaka23
1
720
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
72
12k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.2k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
240
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
210
WCS-LA-2024
lcolladotor
0
490
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
91
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
980
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Designing Powerful Visuals for Engaging Learning
tmiket
0
290
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
92
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
500
Transcript
スケーラビリティのための Sansanアプリケーション基盤 2016年7月28日 #Sansan_gloops
Copyright © 2014 Sansan, Inc. All rights reserved. > 自己紹介
1 • 和田潤也 • 某SIerで8年弱 ⇒ SansanにJOIN • C#、JavaScript 辺り • 主にUI基盤とかを開発していた • 情弱 GitHub: chocolamint
Copyright © 2014 Sansan, Inc. All rights reserved. > え?「インフラ勉強会」…?
2 • インフラの話とはちょっと違います。。。 • アプリケーション基盤の話をします • インフラ要素とも多少絡められたらいいな…
Copyright © 2014 Sansan, Inc. All rights reserved. > スケーラビリティのための仕組み
3 • DBの垂直・水平分散 • 垂直分散 • 役割によってDBを分割 • 水平分散 • ShardingKey によってDBを分割 • ユーザーごとに使うDBを分散するイメージ • メッセージ基盤 • Pub-Sub 型の分散処理基盤 • キューイングサービスを利用
Copyright © 2014 Sansan, Inc. All rights reserved. > DBの分散
4
Copyright © 2014 Sansan, Inc. All rights reserved. > 水平・垂直分散
5 Query Shard Mapping Common Database Use Main data Databases Shard1 Shard3 Shard2 Shard4 News Databases
Copyright © 2014 Sansan, Inc. All rights reserved. > Sansan.Data
6 using (new ShardingScope(shardingKey)) { // ここでの接続は指定されたシャードにいく ... }
Copyright © 2014 Sansan, Inc. All rights reserved. > Sansan.Data
7 Webにおいては ActionFilterAttribute を継承した ShardingFilterAttribute を使って ShardingScope の生成・破棄(Dispose)をしている using (var cn = await ConnectionHelper.OpenDataAsync()) { // 勝手に現在のユーザーが繋ぐべきシャードに繋がる return await cn.Connection.QueryAsync<string>(sql); }
Copyright © 2014 Sansan, Inc. All rights reserved. > メッセージ基盤
8
Copyright © 2014 Sansan, Inc. All rights reserved. > ちょっと前までのツラみ
9 • 統一的な非同期処理基盤がない • Webアプリのボタンクリックで数分かえって来ない • 同時実行できない • 古い自作基盤が並列処理で死ぬ :yami: • リトライで成功するのにアラート • リレー式の処理の滞留具合がわからない • メンテナンス時の停止と開始がツラい
Copyright © 2014 Sansan, Inc. All rights reserved. > 非同期処理基盤がない
10 • Webアプリで数分かかるボタンクリック • 非同期処理するには個別にバッチ開発が必要 Button Click Insert Record with status = 0 Polling with Task Scheduler FooBar.exe FooBarJob Batch Server Web Server
Copyright © 2014 Sansan, Inc. All rights reserved. > 同時実行できない
11 status = 0 を取得 ↓ 何か処理 ↓ status = 1 に更新 複数台(プロセス)で 対象データを取り合うと死ぬ ↓ 複雑な排他制御が必要(しんどい) ↓ スケールしない Batch Server 1 Batch Server 2
Copyright © 2014 Sansan, Inc. All rights reserved. > リトライで成功するのにアラート
12 タスクマネージャーによる プロセスの定期起動 1分後 アクセス失敗 成功 アラート発砲
Copyright © 2014 Sansan, Inc. All rights reserved. > 処理の滞留がわかりづらい
13 スループット? 対象データの流入
Copyright © 2014 Sansan, Inc. All rights reserved. > 停止と開始の嵐
14 バッチA バッチB バッチC バッチD
Copyright © 2014 Sansan, Inc. All rights reserved. 15 殺伐としたバッチ界にメッセージ基盤が!!
Copyright © 2014 Sansan, Inc. All rights reserved. > メッセージ基盤
16 Message Queue Web Server Batch Server Enqueue Dequeue Message Server Execute message concurrency SaaS の キューサービスを利用 Message
Copyright © 2014 Sansan, Inc. All rights reserved. > メッセージ基盤のいいところ
17 • スケールできる • 1プロセス内でマルチスレッドによる並列処理 • キューの種類ごとに並列数を調整可能 • ノードを増やせばさらにスケール可能 • 自動リトライ • 複数回の exponential な自動リトライ • リトライに成功しない場合は dead letter 行き • 自動でアラートメール発砲 • 各処理は冪等であるべき
Copyright © 2014 Sansan, Inc. All rights reserved. > メッセージ基盤のいいところ
18 • 負荷が安定する • セマフォで並列数制御 • メッセージ毎に異なるキューにルーティング • キューの滞留を監視可能 • グラフでモニタリングも出来る • SaaS でアラームを定義できるので滞留を監視できる
Copyright © 2014 Sansan, Inc. All rights reserved. > メッセージ基盤で出来ること
19 • 1つのメッセージに複数の Subscriber を定義可能 • システムイベントに対する複数処理を割り当て • ex) 新しい名刺が登録されたら… • ◦◦処理を実行 • △△処理を実行 • 全て完了したら××処理を実行 • 安全に停止できる • Windows サービスとして実装 • OnStop でキャンセル要求 • 優先度の高いものから処理できる • キューの種類ごとに優先度別のキューを用意できる
Copyright © 2014 Sansan, Inc. All rights reserved. 20 Mail
Queue (High) Mail Queue (Normal) Mail Queue (Low) News Queue (High) News Queue (Normal) News Queue (Low) 4 parallel 8 parallel
Copyright © 2014 Sansan, Inc. All rights reserved. > コードのイメージ
21 MessageQueue queue; while (true) { var message = queue.ReceiveMessage(); if (message != null) Task.Run(() => DispatchMessage(message)); } var msg = new SendMailMessage("title", "body"); await msg.SendAsync(priority: MessagePriority.Background); 標準で用意されているメッセージ • SendMailMessage • SendAllMailMessage • EventMessage
Copyright © 2014 Sansan, Inc. All rights reserved. > Next...
22 • 実際に基盤に乗っかった処理はまだ一部 • 随時効果の高いところから乗せ換え中 • 現状はメッセージ基盤/バッチのログがテキスト • ツラい • fluentd で Elasticsearch に送り込み Kibana で見れる ように • 絶賛対応中