クラウドってなんだろ?
クラウドを活かすアプリケーションの設計とは?
GCPUG Admin
Google Developers Expert
Mercari / Merpay Solution Team
@sinmetal
goo.gl/X54o2S
https://gcpug.jp
クラウドってなんだろ?
データセンター上に存在するハードウェアリソースをAPIを利用して、動的にリソースを借りることができる仕組み。
柔軟に迅速にリソースの提供を受けるために、料金はだいたい従量課金制で、使ったリソースの料金を払う。
2
https://gcpug.jp
クラウドは何がうれしいのか?
3
https://gcpug.jp
クラウドのレイヤー
4
言葉はどんどん増えていってる
https://gcpug.jp
クラウドは何がうれしいのか?
5
https://gcpug.jp
クラウドは壊れないのか?
6
https://gcpug.jp
クラウドは不死鳥のように蘇る
7
https://gcpug.jp
クラウドを活かすには?
8
https://gcpug.jp
リトライ
9
アプリケーション
ストレージ
データベース
キャッシュ
リトライ!
リトライ!
https://gcpug.jp
リトライ
10
アプリケーション
ストレージ
ストレージ
ストレージ
クラッシュ
クラッシュした瞬間送ったリクエストにはレスポンスが返ってこない
https://gcpug.jp
リトライ
11
アプリケーション
ストレージ
ストレージ
ストレージ
クラッシュ
3秒待ってもレスポンスが無ければ、リトライする
https://gcpug.jp
冪等性 (1)
12
アプリケーション
データベース
data : A
key : 1
error
data : A
key : 2
リトライするたびにデータが増えてしまう
https://gcpug.jp
冪等性 (2)
13
アプリケーション
データベース
key : 1
data : A
key : 1
data : A
error
key : 1
data : A
key : 1
data : A
同じ場所を上書きするようにする
https://gcpug.jp
冪等性 (3)
14
本来の冪等性は操作を複数回行っても結果が同じになることを指すけど、実際には操作を複数回行っても不都合が起きなければ問題ないことが多い。
https://gcpug.jp
リクリエイト (1)
15
Compute Engine
Instance
My Application
Compute Engine
Instance
My Application
別のH/Wで再起動される
https://gcpug.jp
リクリエイト (2)
16
https://gcpug.jp
リクリエイト (3)
17
Load Balancer
static contents
api
movie
movie
api
static contents
storage
storage
database
database
cache
cache
マシンスペック
アベイラビリティ
スケーラビリティ
トラフィック
リリース頻度
https://gcpug.jp
クラウドを活かすには?
18
https://gcpug.jp
非同期処理, 分散処理 (1)
19
User
Application
App Engine Confを登録
App Engineに興味があるUserにNotificationを送りたい!
Notification送信...
Notificationをすべて送り終わるまでレスポンスが返ってこない
https://gcpug.jp
非同期処理, 分散処理 (2)
20
User
Application
App Engine Confを登録
Queue
Notification Taskを登録
レスポンスを返す
https://gcpug.jp
非同期処理, 分散処理 (3)
21
https://gcpug.jp
非同期処理, 分散処理 (4)
22
User
Application
Confを登録
Queue
Taskを登録
レスポンスを返す
Worker
Taskの割当
Taskの数に合わせてWorkerの数を変更
Taskが0件の時はWorkerも0台でよい
Cloud Pub/Sub, App Engine Task Queueを利用すれば、運用はGCP任せ
Taskのリトライ, 割当, 残数
https://gcpug.jp
非同期処理, 分散処理 (5)
23
https://gcpug.jp
TaskQueueとプリエンプティブVMを利用して、動画の加工処理を行う分散アーキテクチャ
Task�Queues
Media Storage�Cloud Storage
Meta Data & Workflow�Cloud SQL
Meta Data & Workflow�Cloud Datastore
Media Processing�Compute Engine
Preemptible
Asset Mgmt & Sharing�App Engine
Autoscaling
Upload / �Download Media
Cloud Network�W/ Edge Cache
Media Storage�Cloud Storage
Object Change Notification
Resize Instance group size
24
The Products logos contained in this icon library may be used freely and without permission to accurately reference Google's technology and tools, for instance in books or architecture diagrams.
コンパクトな環境
25
https://gcpug.jp
高速なネットワーク
26
https://gcpug.jp
めんどうだったら
27
GCPのフルマネージドサービスはクラウドに最適化されているものたちなので、アーキテクチャはとても参考になる。
https://gcpug.jp
Google App Engine
28
https://gcpug.jp
App Engine Architecture
29
Google Datacenter
App Engine Services
Frontend
App Engine
Frontend
Static Server
Pending Request Queue
App Server
Datastore
Memcache
Task Queue
Search
URL Fetch
Socket
自分のDeployしたApplicationが動いている場所
https://gcpug.jp
Google BigQuery
30
https://gcpug.jp
Google BigQueryは、なぜはやいのか?
31
https://gcpug.jp
Colossus
32
https://gcpug.jp
Colossusの雰囲気
33
File
1
2
3
4
1
1
2
2
3
3
4
4
1
3
Fileを分割して複数のDiskに複製して保存する。
https://gcpug.jp
Dremel Architecture (BigQueryの裏の仕組み)
HDDから秒間読み込めるデータ容量は百数十MBなので、データを予め100MBほどに分割して、別々のHDDに保存しておく。
クエリ実行時に、必要なテーブルが保存されているHDDに対してDremel Nodeを割り当て、分散処理を行っていく
Dremel Node
Jupiter Network
Storage
Storage
Storage
Storage
Storage
Dremel Node
Dremel Node
Dremel Node
Dremel Node
Dremel Node
Dremel Node
Dremel Node
Dremel Node
Dremel Node
Dremel Node
Dremel Node
Dremel Node
Dremel Node
Dremel Node
Root Node
HDDにHotspotがある場合に備えて、同じファイルを複数のStorageに問い合わせて、最初にレスポンスが返ってきたものを採用している
34
列指向ストレージ
行指向
列指向
35
| | |
| | |
| | |
|
|
|
|
|
|
|
|
|
https://gcpug.jp
Dremel
SELECT
state,
COUNT(1) AS count
FROM
`bigquery-public-data.samples.natality`
WHERE
year = 1987
GROUP BY
state
ORDER BY
count DESC
36
https://gcpug.jp
Dremel v1 Query Processing
37
Leaf
Leaf
Mixer1
Colossus
Jupiter
Leaf
Leaf
Mixer1
Mixer0
Leafはそれぞれ取得したデータに対して以下を実行してMixerに渡す
year = 1987
COUNT
GROUP BY state
MixerはLeafから取得したデータに対して以下を実行して、上のMixerにわたす
COUNT
GROUP BY state
http://gcpug.jp
Google Cloud Dataflow
38
https://gcpug.jp
Google Cloud Dataflow
39
https://gcpug.jp
Google Cloud Dataflow
40
https://gcpug.jp
Thanks you
Slackで待ってます!
https://slack.gcpug.jp
41
https://gcpug.jp