Google Compute EngineとPipe API

144
Google Compute EngineGAE Pipe API @maruyama097 丸山不二夫

description

 

Transcript of Google Compute EngineとPipe API

Page 1: Google Compute EngineとPipe API

Google Compute Engineと GAE Pipe API

@maruyama097 丸山不二夫

Page 2: Google Compute EngineとPipe API

はじめに

Page 3: Google Compute EngineとPipe API

クラウド・サービス提供者とIaaS

o  クラウド・サービスの提供者は、クラウドの管理・制御システムそのものの機能として、プロセッサー資源・ストレージ資源・ネットワーク資源等のリソースを、利用者のニーズに応じて動的に再配分し、特定のユーザー・ドメインをきってサービスを提供するFabricを構成する能力を、基本的には備えている。

o  IaaSは、クラウド・サービスの提供者にとっては、自らの能力のこうした部分を、クラウド・サービスの利用者に、一部解放することと等しい。その意味では、ASP起源のSaaSのサービス提供者の一部を除いて、クラウド・サービスの提供者は、IaaSを提供する能力を、もともと持っていたと考えることが出来る。Azureにしても、Google Compute Engineにしても。

Page 4: Google Compute EngineとPipe API

クラウドのFabricを構成する能力

o  IaaSにしても、そのクラウドのFabricを構成する能力が、そのまま、利用者に提供される訳ではない。

o  ただ、クラウドのFabricを構成する能力自身が、進化していく。その細部を我々が知ることは少ないのだが。

o  そして、その一部は、我々も利用可能になる。GoogleのIaaSを主題とする小論で、Pipeline APIを取り上げたのは、それがクラウド内でFabricを構成する能力と密接に関係していると、筆者が考えているからである。

o  かつては、GoogleのMapReduceは、今とは違うフレームで管理されていたと思う。ただ、今では、それはPipeline APIを通じて管理されていると、筆者は考えている。

Page 5: Google Compute EngineとPipe API

o 高精細ビデオ会議システムの例 n  高いパフォーマン

スと信頼性が要求される

n  自動的にスケール調整が行われる必要がある

AzureのService Model複雑なサービスの構造をモデリングする

Azureの開発段階では、こうした機能が 紹介されたことがあった。

Page 6: Google Compute EngineとPipe API

AzureのService Model 単純なサービスの構造をモデリングする

Public Internet

Fundamental  Services  

Load    Balancer

Frontend  Web  Role  

Background    Process  Role  

テンプレートは自動的に サービスモデルにマップされる

Load Balancer Channel

Endpoint

Interface

Directory Resource

Page 7: Google Compute EngineとPipe API

PaaSとIaaS

o  PaaSも、もちろん、IaaS同様、クラウド・サービス提供者の自在にサービスを提供するFabricを構成出来る能力の基盤の上にたっている。

o  IaaSの場合には、クラウド・サービス利用者に、Fabric構成の広い自由度が認められるのに対して、PaaSの場合には、テンプレートとして与えられた固定的なFabric (必要なScalabiliyは認められるのだが)の上で、主要にアプリケーションを開発・デプロイする。

o  PaaSでは、IaaSでは必要な、システム構成・管理の手間を省き、アプリケーション開発に集中して、すぐにサービスを展開出来るというメリットがあると考えることが出来る。

Page 8: Google Compute EngineとPipe API

PaaSとしてのAzure が想定している 基本的なサービス・モデル

Public Internet

Web Role

Storage Service

Worker Role

Load    Balancer

Page 9: Google Compute EngineとPipe API

何故、今、IaaSなのか?

o  こうしたPaaSのメリットは、ある場合には、弱点にもなる。現実のエンタープライズのシステムでは、サービスの特質や、ある場合には、歴史的な経緯から、PaaSのシステムが想定している単純なFabricより、複雑なシステム構成を取っているところが少なくない。

o  エンタープライズ・システムのクラウド移行にとって、課題の一つは、それまでのソフトウェア資産の継承である。それは多くの場合、システム自体の継承と結びついている。On Premiseへの志向の強さは、そこに起因する。

o  その意味では、IaaSへの注目は、クラウドのエンタープライズへの受容が進む中で、クラウド・サービス提供者側が、よりきめ細かく、エンタープライズ側のニーズに応えようという動きと考えることが出来る。

Page 10: Google Compute EngineとPipe API

クラウド内サービスとIaaS

o  IaaSの柔軟性も、ある場合には、弱点になる。クラウド上にスクラッチからシステムを構築し、それを管理し続けるのは、PaaSと比べるとコストがかかる。

o  だから、IaaSの提供者は、裸のIaaSシステムを提供しているだけでは、十分な競争力を持つことは出来ない。IaaSの利用者にとって、彼らのサービス構築に役立つ、様々なクラウド内のサービスを提供することによって、IaaS間の競争で優位に立とうとする。

o  IaaSの提供者の、クラウド内サービスのメニューは多様である。IaaSの利用者が、システムを選択するにあたって、それは少なくない意味を持っている。

Page 11: Google Compute EngineとPipe API

Agenda

小論では、次のような角度から、GoogleのIaaS、Google Compute Engineの特徴を考えてみようと思う。

o  Googleクラウドの、耐障害性・高可用性 o  Googleのエンタープライズ・クラウドの取り組み

o  Google Compute Engine o  Googleクラウドが提供する各種サービス o  クラウド内サービスを結合するPipe API o  GAE + GCEのユースケース

Page 12: Google Compute EngineとPipe API

Googleクラウドの、 耐障害性・高可用性

クラウドを技術的に特徴づけるものは、コモディティ化したマシンのScale-OutアーキテクチャーによるScalabilityとそのAvailabilityである。 ただ、近年、クラウドの障害も少なくない。Googleのクラウドも例外ではない。まず、Googleクラウドの耐障害性を高める取り組みを見ておこう。

Page 13: Google Compute EngineとPipe API

2009年7月、Google大規模障害

o  2009年7月2日, 6:45 AM から12:35 PM まで、Google App Engineに大規模な障害発生。

o  この障害の根本的な原因は、データセンタ内のノードが、

サーバー側できちんとしたチェックを行わずに、不適切に構成されたFileHandleを送りつけたことに起因するGFS Master serverのバグであった。これを処理しようとして、Masterは、スタック・オーバーフローを起こした。

o  障害報告 https://groups.google.com/forum/?fromgroups#!msg/google-appengine/6SN_x7CqffU/ecHIgNnelboJ

Page 14: Google Compute EngineとPipe API

Transactions Across Datacenters (Weekend Project)

o  この障害事故の少し前、2009年5月27日 Google IO で、Ryan Barrettは、自らのWeekend Projectとして、データセンターをまたいだシステムを提案していた。

o  http://www.google.com/intl/ja/events/io/2009/sessions/TransactionsAcrossDatacenters.html

n  what if your entire datacenter falls off the face of the earth? This talk will examine how current large scale storage systems handle fault tolerance and consistency, with a particular focus on the App Engine datastore. We'll cover techniques such as replication, sharding, two phase commit, and consensus protocols (e.g. Paxos), then explore how they can be applied across datacenters.

Page 15: Google Compute EngineとPipe API

Google、2009年8月1日、 GFSのデザインの見直しを示唆

o  事故直後の2009年8月1日、Sean Quinlanは、ACMとのインタビューに応え、GFSのデザインの見直しを示唆。 ”GFS: Evolution on Fast-forward” 以下、その要旨。 http://queue.acm.org/detail.cfm?id=1594206

o  GFSの単一マスターで行くという決定は、実際には、設計の非常に早い段階でなされたものだ。主要には、デザインをシンプルなものにするというのが、その理由だ。

o  ただ、問題は、すぐに起きていた。ストレージの容量が、数百テラからペタバイトに、さらには数十ペタに増大するにつれて、マスターが維持しなければならないメタデータの割合は、増えていった。

Page 16: Google Compute EngineとPipe API

GFS: Evolution on Fast-forward

o  同様に、データのボリュームとともに、リカバリーのデータを探す為にメタデータをスキャンするというような操作がリニアなスケールで増えていく。こうして、マスターに要求される仕事の量は、本質的に増大する。

o  GFSが、いまや、多くの挑戦にさらされているのは、疑問の余地はない。一例を挙げれば、不断に増大するユーザーの大群と直面していて遅延が大きな問題となるアプリケーションを、本来は、バッチ・システムの効率を上げる為にデザインされたシステムの上でサポートしていることの、不格好さは、誰の目にも明らかである。

Page 17: Google Compute EngineとPipe API

GFS: Evolution on Fast-forward

o  BigTableの登場は、この点では、いくらかの助けにはなった。ただ、明らかになったのは、BigTable は、実際には、GFSとは、最良の組み合わせではなかったということだ。事実、この組み合わせは、GFSシステムの単一マスターのデザインのボトルネックとしての限界を、他の場合よりも、はるかに明らかなものとしただけだった。

o  これした理由から、Googleの技術者達は、過去2年間というもの、BigTableの利点を最大限生かしながら、現GFSに取っては特に困難であると証明されているいくつかの問題を攻略する、新しい分散マスターシステムのデザインに取り組んできた。

Page 18: Google Compute EngineとPipe API

HDFSのAvatar Node

o  ちなみに、Facebookが、HDFSのMaster Nodeの二重化、いわゆ、Avatar Nodeの実装の次の論文を発表したのは、2011年のSIGMODでのことであった。

o  “Apache Hadoop goes Realtime at Facebook” http://dl.acm.org/citation.cfm?id=1989438&bnc=1

Page 19: Google Compute EngineとPipe API

2009年9月、Bigtableの見直し

o  2009年9月14日、Ryan Barrettは、“Migration to a Better Datastore”を発表http://googleappengine.blogspot.jp/2009/09/migration-to-better-datastore.html

o  Megastore replication saves the day! Megastore is an internal library on top of Bigtable that supports declarative schemas, multi-row transactions, secondary indices, and recently, consistent replication across datacenters.

Page 20: Google Compute EngineとPipe API

2011年1月 Megastore: Providing Scalable, Highly Available Storage for Interactive Services

o  http://www.cidrdb.org/cidr2011/Papers/CIDR11_Paper32.pdf

Page 21: Google Compute EngineとPipe API

Megastore

Page 22: Google Compute EngineとPipe API

Googleのエンタープライズ・クラウドの取り組み

Google App Engine for Businessは、2010年5月に、大々的に発表されたが、一年後の2011年5月には、開発中止となった。

Page 23: Google Compute EngineとPipe API

Google App Engine for Business

o  2010年5月19日 Google I/Oで、企業が直面している問題を解決するために、新しいバージョンのGAE4Bをスクラッチから開発すると発表。

o  GoogleとVMwareとの協業。Google I/Oでの、VMware CEO Paul Maritzの発言 http://www.youtube.com/GoogleDevelopers#p/c/02292AD8CFFE1349/7/KzTgzKkBtqE

Page 24: Google Compute EngineとPipe API
Page 25: Google Compute EngineとPipe API

VMware CEO Paul Maritz

Page 26: Google Compute EngineとPipe API

当時の問題意識: App Engineの エンタープライズ利用での問題

o  なぜ、GAE4Bを開発したのか? 当時のGoogleの問題意識を振り返ることは、意味がある。App Engineは、エンタープライズ・システムとしては、次のような問題があったとされていた。

o  On Premise側では再利用できない、GAE独自のプログラミング・モデル。

o  SQLデータベースの未サポート。 o  機能上の制限(30秒ルール等)。

Page 27: Google Compute EngineとPipe API

どのようなシステムを構想していたか

o  新しいApp Engine for Businessは、次のような特徴を備えているとされていた。

o  Spring Frameworkの採用により、PublicとOn Premiseのシステムとの間での連続的な移行可能性とHybrid Systemの構築の容易さを獲得。

o  Java/Spring開発者の従来のスキルを、クラウド・プログラミングに活用ができる。

o  大規模なBigTableに加えて、標準的なSQLデータベースのアクセスが出来る。

o  SLA/サポートの保障。

Page 28: Google Compute EngineとPipe API

Google App Engine for Business 開発中止 2011年5月12日

o  GAE4B が予定していた機能の殆どは App Engine に組み込まれ、お支払い頂いているお客様であればそれらの機能が使用できます。

o  SLA、独自ドメインでの SSL、サポート、新しいビジネスに適した利用規約、オフラインでの支払いなどがこれにあたります。Domain Console は現在 Trusted Tester を実施しており、しばらくはそのままの状態が続きます。

o  今後も GAE4B は単独のサービスとして提供されることはありません。

http://googledevjp.blogspot.jp/2011/05/google-app-engine-preview.html

Page 29: Google Compute EngineとPipe API

GAE1.5の発表 2011年5月10日

o  Backends: developer-controlled, long-running, addressable sets of instances

o  Pull Queues:you can write a Backend to do some background processing and pull 1, 10, or 100s of tasks off the Pull Queue

o  High Replication Datastore as default: setting HRD as the default for all new apps created, lowering the price of HRD storage from $0.45 down to $0.24, and encouraging everybody to begin plans to migrate.

http://googleappengine.blogspot.jp/2011/05/app-engine-150-release.html

Page 30: Google Compute EngineとPipe API

Google Compute Engine

2012年6月28日 http://cloud.google.com/products/compute-engine.html https://developers.google.com/events/io/sessions/gooio2012/313/ https://developers.google.com/events/io/sessions/gooio2012/302/

Page 31: Google Compute EngineとPipe API

CLI

API

Persistent Disk

VM

Internet

UI

Code

Private Network

Local Disk

Cloud Storage

Project

VM VM

Google Compute Engineの

Page 32: Google Compute EngineとPipe API

CLI

API

Persistent Disk

VM

Internet

UI

Code

Private Network

Local Disk

Cloud Storage

Project

VM VM

API Basics

Page 33: Google Compute EngineとPipe API

APIの基本はREST JSON over HTTP

o  APIが対象とする主なリソース n  プロジェクト n  インスタンス n  ネットワークとファイアウォール n  ディスクとスナップショット n  ゾーン

o  アクション n  GET n  POST (create) と DELETE n  更新用に、カスタムの‘verbs’

o  認証  OAuth2

Page 34: Google Compute EngineとPipe API

CLI

API

Persistent Disk

VM

Internet

UI

Code

Private Network

Local Disk

Cloud Storage

Project

VM VM

プロジェクト

Page 35: Google Compute EngineとPipe API

プロジェクト

o  プロジェクトは、全てのリソースのコンテナで、次のような情報を含んでいる。

o  チームを構成するメンバー情報 o  グループのリソースの所有情報 o  課金情報

Page 36: Google Compute EngineとPipe API

CLI

API

Persistent Disk

VM

Internet

UI

Code

Private Network

Local Disk

Cloud Storage

Project

VM VM

インスタンス

Page 37: Google Compute EngineとPipe API

インスタンスは、LINUXのVM ハードは、Intel Sandy Bridge

o  Root権限を持つ、Ubuntu, CentOS o  いくつかのライブラリーは、プレインストールされている o  仮想CPUは、1,2,4,8個、huperthreadに一対一対応 o  仮想CPUごとに、3.75GB RAM o  CPUごとに、420GB以上の一時ディスク o  新しいパフォーマンスのメトリックス 

n  GCEU: Google Compute Engine Unit n  仮想CPUあたり 2.75 GCEUs

o  もっと小さいサイズのマシンも、準備中 o  KVM Hypervisor + Linux cgroups

Page 38: Google Compute EngineとPipe API

CLI

API

Persistent Disk

VM

Internet

UI

Code

Private Network

Local Disk

Cloud Storage

Project

VM VM

ネットワーク

Page 39: Google Compute EngineとPipe API

ネットワーク

o  Private Virtual Network n  プロジェクトごとに隔離されたネットワーク n  Private IPv4 space (RFC 1918) n  Layer 3 ネットワーク n  地理的なリージョンをまたいだフラットなネットワーク n  内部的には、VM name = DNS name

o  Internet Access n  External IPs: n  1-to-1 NAT / Built in firewall system n  Outgoing SMTP blocked / UDP,TCP,ICMP

のみ

Page 40: Google Compute EngineとPipe API

CLI

API

Persistent Disk

VM

Internet

UI

Code

Private Network

Local Disk

Cloud Storage

Project

VM VM

ストレージ -- 永続ディスク

Page 41: Google Compute EngineとPipe API

ストレージ -- 永続ディスク

o  高速の、整合性を保証されたパフォーマンス o  APIを通じてアクセスする o  ‘zone’に置かれる o  一つのインスタンスからはR/W可能 o  複数のインスタンスからは、R/O o  暗号化されている

Page 42: Google Compute EngineとPipe API

CLI

API

Persistent Disk

VM

Internet

UI

Code

Private Network

Local Disk

Cloud Storage

Project

VM VM

ストレージ – 一時ディスク

Page 43: Google Compute EngineとPipe API

ストレージ – 一時ディスク

o  現在は、全てのインスタンスをブートするのに利用 o  インスタンスとともに、生成・消滅する o  巨大な‘拡張’デバイス o  同じ物理マシン上に置かれる o  4CPU以上では、専用ディスクが割り当てられる o  暗号化

Page 44: Google Compute EngineとPipe API

CLI

API

Persistent Disk

VM

Internet

UI

Code

Private Network

Local Disk

Cloud Storage

Project

VM VM

ストレージ Google Cloud Storage

Page 45: Google Compute EngineとPipe API

ストレージ Google Cloud Storage

o  インターネット上の、オブジェクト・ストア o  グローバル APIベースのアクセス o  データの取り出し・格納に非常に便利 o  サービスのアカウントで、摩擦なしにアクセス出来る

Page 46: Google Compute EngineとPipe API

CLI

API

Persistent Disk

VM

Internet

UI

Code

Private Network

Local Disk

Cloud Storage

Project

VM VM

Locality Managing Location and Availability

Page 47: Google Compute EngineとPipe API

Locality Managing Location and Availability

o  Region: 地理的に離れていて、ルーティングされている o  Zone: 障害からの物理的な隔離が行われる範囲 o  制限プレビュー版では、3 Zoneが提供されているが、今

後、その数を増やしていく

Page 48: Google Compute EngineとPipe API
Page 49: Google Compute EngineとPipe API
Page 50: Google Compute EngineとPipe API
Page 51: Google Compute EngineとPipe API

Googleクラウドが提供する 各種サービス

Page 52: Google Compute EngineとPipe API

各種サービスの発表時期

p  Google Datastore 2011/05/10 p  GAE4Bの断念 2011/05/12 p  App Engine MapReduce 2011/05/23 p  GAE Pipeline API 2011/05/28

p  Google Cloud SQL 2011/10/06 p  Google Cloud Storage 2011/10/11

p  Google BigQuery 2012/05/01 p  Google Compute Engine 2012/06/28

Page 53: Google Compute EngineとPipe API

Google DataStore

Google DataStoreは、Google Bigtableの機能拡張版である。 2011年5月10日 発表 https://developers.google.com/appengine/docs/python/datastore/overview

Page 54: Google Compute EngineとPipe API

Google DataStore

o  マスター/スレーブ データストア n  マスター/スレーブ レプリケーション システムを使用し、

データが書き込まれるとデータは非同期に複製される。 n  読み取りとクエリに対して強い整合性 n  データ センターにトラブルや計画的ダウンタイムが発

生すると、一時的に利用できなくなる。 o  高レプリケーション データストア(デフォールト)

n  データを、Paxos アルゴリズムに基づいて、複数(3っつのZone)のデータ センターに複製。

n  非常に高い可用性を実現(書き込みの遅延は高い)。 n  結果整合性を保証。 n  マスター/スレーブ方式の約3倍のリソース消費。

Page 55: Google Compute EngineとPipe API

Datastore/Megastore/Bigtable

http://www.slideshare.net/ikailan/introducing-the-app-engine-datastore

Page 56: Google Compute EngineとPipe API

エンティティとプロパティ

o  データストアのデータ オブジェクトは「エンティティ」と呼ばれ、1 つ以上の「プロパティ」を持つ。

o  各エンティティはそれぞれを一意に識別する「キー」を持つ。最も単純なキーは、「種類(kind)」とデータストアによって付与される「エンティティ ID」である。

o  プロパティは、整数、浮動小数点値、文字列、日付、バイナリ データなどのいずれかのデータ型の名前付きの値。

o  データストア エンティティはスキーマレス。同じ種類の 2 つのエンティティのプロパティが同じである必要はなく、同じプロパティに対して同じ値の型を使用する必要もない。

Page 57: Google Compute EngineとPipe API

クエリとインデックス トランザクションとエンティティ グループ

o  データストアのクエリではインデックスを使用する。インデックスとは、クエリ結果が希望する順序で含まれる表である。App Engine アプリケーションでは、設定ファイルでインデックスを定義する。

o  アプリケーションでデータストアのエンティティに変更を加えると、データストアは正しい結果でインデックスを更新する。アプリケーションでクエリを実行すると、データストアは対応するインデックスから結果を直接フェッチする。

o  Transaction API を使用すると、1 つのトランザクション内で 1 つのエンティティに対して複数の処理を実行できる。

o  エンティティ グループは、エンティティ間の関係の階層構造で定義される。

Page 58: Google Compute EngineとPipe API
Page 59: Google Compute EngineとPipe API

Datastoreでは、 SQLのサブセットが使える

o  Filters n  SELECT * FROM Table WHERE A=1 AND

(B=2 OR C=3) o Sorting

n  SELECT * FROM Table ORDER BY A, B DESC

o  Projections / Index-Only Queries n  SELECT A, B FROM Table

Page 60: Google Compute EngineとPipe API

制限

o  エンティティの最大サイズ 1 MB o  エンティティの全インデックスの値の最大数  5,000 個

n  エンティティは、インデックスで、そのエンティティを参照する行と列の各組み合わせに対して 1 つの値を使用する。インデックスに登録されたプロパティが複数の値を持つ場合、値が繰り返されて表に複数の行が必要になるので、エンティティのインデックス値の数が増える可能性がある。

Page 61: Google Compute EngineとPipe API

High Replication Master/Slave Performance

Put/delete latency 1/2x–1x 1x

Get latency 1x 1x

Query latency 1x 1x

Consistency

Put/get/delete Strong Strong

Most queries Eventual Strong

Ancestor queries Strong Strong

Occasional planned read-only period No Yes

Unplanned downtime Extremely rare; no data loss.

Rare; possible to lose a small % of writes occurring near downtime (recoverable after event)

Page 62: Google Compute EngineとPipe API

Free quota per app per day

Pricing if you exceed your free quota

Hosting Free quota per app per day

Price

On-demand Frontend Instances

28 free instance hours

$0.08 / hour

Reserved Frontend Instances

$0.05 / hour

High Replication Datastore

1G $0.24 / G / month

Outgoing Bandwidth 1G $0.12 / G Incoming Bandwidth 1G Free

APIs

Datastore API 50k free read/write/small

$0.10/100k write ops $0.07/100k read ops $0.01/100k small ops

Blobstore API 5G $0.13 / G / month

Page 63: Google Compute EngineとPipe API

App Engine MapReduce

A model to do efficient distributed computing over large data sets. 2011年5月11日発表 http://code.google.com/p/appengine-mapreduce/ http://www.youtube.com/watch?v=EIxelKcyCC0

Page 64: Google Compute EngineとPipe API

App EngineからMapReduceを 利用可能にする際、考えたこと

o  スケールの次元の追加 n  非常に沢山のアプリが走っている n  それらのアプリが同時にMapReduceを走らせる

o  隔離:そうしたアプリが、他のアプリのパフォーマンスに影響を与えるべきではない。

o  リミットの評価:一日分のリソースを、15分間で使い切り、オンライン・トラフィックも殺してしまうことを誰も望まない

o  非常に遅い実行:無料のアプリは、リソースのリミット以下にとどまりながら、とても遅く実行されることを望む。

o  保護:悪意のあるApp Engineの利用者から、システムを守る。

Page 65: Google Compute EngineとPipe API

Pipeline API o  複雑な仕事を、つなげて一つにまとめる新しいAPI o  Mapper + Shuffler + Reducer をつなぐ、接着剤 o  MapReduceのライブラリーは、完全に、Pipelineと統合

されている。

Page 66: Google Compute EngineとPipe API
Page 67: Google Compute EngineとPipe API
Page 68: Google Compute EngineとPipe API
Page 69: Google Compute EngineとPipe API

MapPipeline

ShufflePipeline

Page 70: Google Compute EngineとPipe API
Page 71: Google Compute EngineとPipe API

ReducePipeline

CleanupPipeline

Page 72: Google Compute EngineとPipe API

class MyPipeline(base_handler.PipelineBase): def run(self, parameter): output = yield mapreduce_pipeline.MapreducePipeline( “name_of_pipeline_step”, “main.map_function”, “main.reduce_function”, “mapreduce.input_readers.DatastoreInputReader”, “mapreduce.output_writers.FileOutputWriter”, mapper_params=() reducer_params=(), shards=16) yield AnotherPiprline(output)

App Engine MapReduce

Page 73: Google Compute EngineとPipe API

Google Cloud SQL

Google Cloud SQL は、Googleクラウド内のMySQLデータベースである。2011年10月6日、発表。 https://developers.google.com/cloud-sql/

Page 74: Google Compute EngineとPipe API

Google Cloud SQLの特徴

o  MySQLデータベースを、クラウド上で動かす。 o  地理的にはなれたデータセンター間で、データベースの複

製を同期することが出来る。 o  mysqldumpを利用して、データベースのimport,

exportが出来る。 o  Java, PythonからのAPIが使える。 o  コマンドライン・ツールがある。 o  Google API Consoleで、SQLが使える。

Page 75: Google Compute EngineとPipe API

制限

o  一つのインスタンスのサイズは、10GBまで。 o  ユーザー定義関数は、サポートされていない。 o  MySQLのレプリカはサポートされない。 o  次のSQL文は、サポートされない。

n  LOAD DATA INFILE n  SELECT ... INTO OUTFILE/DUMPFILE n  INSTALL/UNINSTALL PLUGIN ... n  CREATE FUNCTION ... n  LOAD_FILE()

Page 76: Google Compute EngineとPipe API

Packages Billing Plan Tier RAM Included

Storage Included I/O per Day

Charge per Day

D1 0.5GB 1GB 850K $1.46

D2 1GB 2GB 1.7M $2.93

D4 2GB 5GB 4M $5.86

D8 4GB 10GB 8M $11.71

Resource Charge D1 Database Instance (0.5GB RAM) $0.10 per hour D2 Database Instance (1GB RAM) $0.19 per hour D4 Database Instance (2GB RAM) $0.38 per hour D8 Database Instance (4GB RAM) $0.77 per hour 1GB Storage $0.24 per month I/O $0.10 per Million

Per Use Billing Plan

Page 77: Google Compute EngineとPipe API

Google Cloud Storage

Fast, scalable, highly available object store  2011年10月11日発表。 https://developers.google.com/appengine/docs/python/googlestorage/

Page 78: Google Compute EngineとPipe API

Google Cloud Storageとは?

o  Google Cloud Storageは、Googleのクラウド・インフラの上に、データを格納し、それにアクセスする、 RESTful サービス。このサービスは、Googleクラウドのパフォーマンスとスケーラビリティを、先進的なセキュリティ技術と共有の能力とに結びつける。

o  全てのデータは、複数のデータセンタに複製される。 o  書き込みと、読み出しのデータの整合性は保たれる。 o  オブジェクトのサイズは、数テラバイトまで可能。アップ

ロード、ダウンロードでレジュームが可能。range-GETをサポートしている。

o  バケットの名前空間は、ドメイン・スコープになっている。

Page 79: Google Compute EngineとPipe API

Monthly Usage Price (per GB) First 0 - 1TB $0.12 Next 9TB $0.105 Next 90TB $0.095 Next 400TB $0.085 Additional Storage Contact us

Monthly Usage

Network (Egress) - Americas and EMEA* (per GB)

Network (Egress) - Asia-Pacific (per GB)

Network (Ingress)

0 - 1TB $0.12 $0.21 Free

Next 9TB $0.11 $0.18 Next 90TB $0.08 $0.15 Additional Data Transfer

Contact us

Storage

Network

Page 80: Google Compute EngineとPipe API

PUT, POST, GET bucket**, GET service** Requests (per 1,000 requests/month)

GET, HEAD Requests (per 10,000 requests/month)

DELETE Requests

$0.01 $0.01 Free

Requests

Page 81: Google Compute EngineとPipe API

クラウド内サービスを結合する Pipeline API

The Google App Engine Pipeline API connects together complex, time-consuming workflows. 2011年5月28日 発表 http://code.google.com/p/appengine-pipeline/ https://developers.google.com/events/io/sessions/gooio2012/307/

Page 82: Google Compute EngineとPipe API

Overview

o  Google App Engine Pipeline API は、複雑で時間を消費するワークフロー(人間の仕事も含む)を、一つに結合する。

o  Pipeline APIの目標は、柔軟さ、ワークフローの再利用、そして、テスト可能性である。

o  このAPIの第一のユースケースは、App Engineの様々のMapReduceを、計算パイプラインに結合することである。

Page 83: Google Compute EngineとPipe API

Job Graphs

[ (x - y) * (x - z) ] - 2

http://code.google.com/p/appengine-pipeline/wiki/GettingStartedJava

Page 84: Google Compute EngineとPipe API

immediate jobs

class DiffJob extends Job2<Integer, Integer, Integer> { @Override public Value<Integer> run(Integer a, Integer b) { return immediate(a - b); } } class MultJob extends Job2<Integer, Integer, Integer> { @Override public Value<Integer> run(Integer a, Integer b) { return immediate(a*b); } }

Page 85: Google Compute EngineとPipe API

Generator Jobs

class ComplexJob extends Job3<Integer, Integer, Integer, Integer> { @Override public Value<Integer> run(Integer x, Integer y, Integer z) { DiffJob diffJob = new DiffJob(); MultJob multJob = new MultJob(); FutureValue<Integer> r = futureCall(diffJob, immediate(x), immediate(y)); FutureValue<Integer> s = futureCall(diffJob, immediate(x), immediate(z)); FutureValue<Integer> t = futureCall(multJob, r, s); FutureValue<Integer> u = futureCall(diffJob, t, immediate(2)); return u; } }

FutureValue<Integer> r =     futureCall(diffJob, immediate(x), immediate(y));

Page 86: Google Compute EngineとPipe API

ComplexJob and the child graph

Page 87: Google Compute EngineとPipe API

Running Pipelines

PipelineService service =   PipelineServiceFactory. newPipelineService(); String pipelineId =   service. startNewPipeline( new ComplexJob(), 11, 5, 7); // Later, check on the status and get the final output JobInfo jobInfo = service. getJobInfo(pipelineId); JobInfo.State state = jobInfo. getJobState(); if (JobInfo.State.COMPLETED_SUCCESSFULLY                                == state){ System.out.println("The output is " +           jobInfo. getOutput()); }

Page 88: Google Compute EngineとPipe API

PipelineService

<T1,T2,T3> java.lang.String startNewPipeline( Job3<?,T1,T2,T3> jobInstance, T1 arg1, T2 arg2, T3 arg3, JobSetting... settings) void stopPipeline(String pipelineHandle); void deletePipelineRecords(String pipelineHandle); void submitPromisedValue(String promiseHandle, Object value);

Page 89: Google Compute EngineとPipe API

Promised Values and External Agents

o  PromisedValueは、ある非同期の外部のエージェントが値を提供するとき、埋められるであろう、値のスロットを表現している。このメカニズムは、このフレームワークが、MapReduceのような他のフレームワークに呼び出しを行って、同時に、パイプライン中に、人間からの入力を待つことを可能にする。

o  次のパイプラインは、人間から三つの整数を受け取り、それをComplexJobに入力として渡し、その答えを人間に返し、さらにもう一つ整数を要求し、追加の整数を、ComplexJobの結果と掛けている。

Page 90: Google Compute EngineとPipe API
Page 91: Google Compute EngineとPipe API

class ExternalAgentJob extends Job1<Integer, String> { @Override public Value<Integer> run(String userEmail) { // Invoke ComplexJob on three promised values PromisedValue<Integer> x = newPromise(Integer.class); PromisedValue<Integer> y = newPromise(Integer.class); PromisedValue<Integer> z = newPromise(Integer.class); FutureValue<Integer> intermediate = futureCall(new ComplexJob(), x, y, z); // Kick off the process of retrieving the data from the external agent getIntFromUser("Please give 1st int", userEmail, x.getHandle()); getIntFromUser("Please give 2nd int", userEmail, y.getHandle()); getIntFromUser("Please give 3rd int", userEmail, z.getHandle()); // Send the user the intermediate result and ask for one more integer FutureValue<Integer> oneMoreInt = futureCall(new PromptJob(), intermediate, immediate(userEmail)); // Invoke MultJob on intermediate and oneMoreInt return futureCall(new MultJob(), intermediate, oneMoreInt); }

Page 92: Google Compute EngineとPipe API

public static void getIntFromUser(String prompt, String userEmail, String promiseHandle) { // 1. Send the user an e-mail containing the prompt. // 2. Ask user to submit one more integer on some web page. // 3. promiseHandle is a query string argument // 4. Handler for submit invokes submitPromisedValue(promiseHandle, value) } } class PromptJob extends Job2<Integer, Integer, String> { @Override public Value<Integer> run(Integer intermediate, String userEmail) { String prompt = "The intermediate result is " + intermediate + "." + " Please give one more int"; PromisedValue<Integer> oneMoreInt = newPromise(Integer.class); ExternalAgentJob.getIntFromUser(prompt, userEmail, oneMoreInt.getHandle()); return oneMoreInt; } }

Page 93: Google Compute EngineとPipe API

Pythonでの定義

class Add(pipeline.Pipeline): def run(self, a, b): return a + b class Multiply(pipeline.Pipeline): def run(self, a, b): return a * b class LinearFunc(pipeline.Pipeline): def run(self, x, slope=1, offset=0): # y = m*x + b mx = yield Multiply(x, slope) yield Add(mx, offset)

http://code.google.com/p/appengine-pipeline/wiki/GettingStarted

Page 94: Google Compute EngineとPipe API

Pythonでの呼び出し

# Create it like an object job = LinearFunc(6, slope=3.5, offset=7) job.start() pipeline_id = job.pipeline_id # Access outputs later job = LinearFunc.from_id(pipeline_id) if job.has_finalized:   job.outputs.default.value == 28 # True

Page 95: Google Compute EngineとPipe API

Pipelineは、どのように動くのか?

http://static.googleusercontent.com/external_content/untrusted_dlcp/www.google.com/en//events/io/2011/static/presofiles/google_io_2011_pipeline_api.pdf

Page 96: Google Compute EngineとPipe API

Pipelineは、どのように動くのか? 次のサンプルで見てみよう

class Add(pipeline.Pipeline): def run(self, *values): return sum(values)

class Multiply(pipeline.Pipeline): def run(self, i=1, j=1, k=1): return i * j * k

class Polynomial(pipeline.Pipeline): def run(self, x, A, B, C): # y = A*x^2 + B*x + C Ax_2 = yield Multiply(A, x, x) Bx = yield Multiply(B, x) yield Add(Ax_2, Bx, C)

Page 97: Google Compute EngineとPipe API

先のコードでは、変数 A,B,C,X と関数Multiply, Addの定義、中間結果の変数 Ax_2,Bx が与えられている

Page 98: Google Compute EngineとPipe API

yieldが生み出す結果を入れる スロットと、全てのスロットが満た された時にのみ、制御を次に進 めるBarrierが、用意される。

Page 99: Google Compute EngineとPipe API

AX_2,BXの計算を始める。 それぞれは、独立した処理で 構わない。

Page 100: Google Compute EngineとPipe API

計算結果を、それぞれの スロットに格納する。

Page 101: Google Compute EngineとPipe API

スロットが満たされると、それを Barrierに通知する。

Page 102: Google Compute EngineとPipe API

Barrierは、全てのスロットが 埋まった時、次のステップを 実行する。

Page 103: Google Compute EngineとPipe API

準備ができている値を使って 次の計算が行われる。

Page 104: Google Compute EngineとPipe API

結果は、用意されたスロットに 格納される。

Page 105: Google Compute EngineとPipe API

DatastoreのJoinに MapReduce/Pipelineを利用する

http://static.googleusercontent.com/external_content/untrusted_dlcp/www.google.com/en//events/io/2011/static/presofiles/google_io_2011_pipeline_api.pdf

Page 106: Google Compute EngineとPipe API

2つのデータストアPRODUCTとSALESの エンティティを、キー SKU でジョインするのに、 MapReduceを使うサンプル

Page 107: Google Compute EngineとPipe API
Page 108: Google Compute EngineとPipe API
Page 109: Google Compute EngineとPipe API
Page 110: Google Compute EngineとPipe API

class JoinOnSKU(base_handler.PipelineBase): def run(self): product_data = yield DatastrorageMapperPipeline( mapper_spec = ‘main.Datastore_map’ , entity_kind_spec = ‘main.ProductDescription’ , shards = 16 ) sales_data = yield DatastoreMapperPipeline( mapper_spec = ‘main.Datastore_map’ , entity_kind_spec = ‘main.ProductSales’ , shards = 16 ) all_data = yield pipeline_common.Extend(product_data, sales_data) shuffled_data = yield mapreduce_pipeline.ShufflePipeline( ‘Shuffle by Product ID’ , all_data, shards = 16)

Page 111: Google Compute EngineとPipe API

join_by_user_id = yield mapreduce_pipeline.ReducePipeline( ‘Join by SKU ID’ , ‘main storage_reduce’ , output_writer_spec = ‘mapreduce.output_writers.FileOutputWriter’ , params = { ‘output_writer’ : { ‘filesystem’: ‘gs’ . ‘gs_bucket_name’: ‘datastore_export’ , ‘output_sharding’: ‘none’ } }, filenames = shuffled_data) def storage_reduce(key, value) : # Do something with the resulting values # A’JOIN , a count, etc. etc. yield (‘%s¥n’ % result )

Page 112: Google Compute EngineとPipe API
Page 113: Google Compute EngineとPipe API

product_data = yield DatastrorageMapperPipeline( mapper_spec = ‘main.Datastore_map’ , entity_kind_spec = ‘main.ProductDescription’ , shards = 16 )

Page 114: Google Compute EngineとPipe API

sales_data = yield DatastoreMapperPipeline( mapper_spec = ‘main.Datastore_map’ , entity_kind_spec = ‘main.ProductSales’ , shards = 16 )

Page 115: Google Compute EngineとPipe API

shuffled_data = yield mapreduce_pipeline.ShufflePipeline( ‘Shuffle by Product ID’ , all_data, shards = 16)

Page 116: Google Compute EngineとPipe API

join_by_user_id = yield mapreduce_pipeline.ReducePipeline( ‘Join by SKU ID’ , ‘main storage_reduce’ , output_writer_spec = ‘mapreduce.output_writers.FileOutputWriter’ , params = { ... } filenames = shuffled_data)

Page 117: Google Compute EngineとPipe API
Page 118: Google Compute EngineとPipe API

Google BigQuery

テラバイトのデータを、ボタン一つのクリックで分析する。 2012年5月1日 発表 https://developers.google.com/bigquery/ https://developers.google.com/events/io/sessions/gooio2012/312/

Page 119: Google Compute EngineとPipe API

Google BigQuery

o  Google BigQuery サービスは、非常に大きなデータセット、可能的には数百万行のデータに対して、SQL-likeな検索を行うことを可能とする。そのデータは、自分のものであってもいいし、誰かが共有してくれたものでもいい。

o  BigQueryは、非常に巨大な、追加しか認められないような少数のテーブルからなるデータのインタラクティブな解析に最適である。

o  もっと、伝統的なリレーショナル・データベースに対しては、BigQueryの代わりに、Google Cloud SQL を使った方がいいかもしれない。

Page 120: Google Compute EngineとPipe API

SELECT timestamp, title, COUNT(*) as cnt FROM publicdata:samples.wikipedia WHERE LOWER(title) CONTAINS ‘speed’ AND vp_namespace = 0 GROUP BY title, timestamp ORDER BY cnt DESC LIMIT 20;

Wikipediaの中から、’speed’という ことばを含むタイトルを持つ論文を 探し出す。

Page 121: Google Compute EngineとPipe API

BigQueryの特徴

o  スピード – 数百万行を数秒で解析する o  スケール – テラバイトのデータ、数兆のレコード o  単純さ – Googleのインフラの上で動く、SQL-likeな検

索言語 o  共有 – Googleアカウントを利用した、グループ・ベース、

個人ベースの強力なパーミッション機能。 o  セキュリティ – セキュアなSSLアクセス o  複数のアクセス方法

n  BigQueryブラウザ n  bq コマンドライン・ツール n  REST API n  Google Apps Script

Page 122: Google Compute EngineとPipe API

SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus;

How many works of Shakespeare are there?

Page 123: Google Compute EngineとPipe API

SELECT corpus, sum(word_count) AS wordcount FROM publicdata:samples.shakespeare GROUP BY corpus ORDER BY wordcount DESC; Which are the longest works?

Page 124: Google Compute EngineとPipe API

https://developers.google.com/events/io/sessions/gooio2012/307/

Page 125: Google Compute EngineとPipe API

class IteratorPipeline(base_handler.PipelineBase): def run(self, entity_type): output = yield mapreduce_pipeline.MapperPipeline( “Datastore_Iterator_” + entity_type, “main.datastore_map”, “mapreduce.input_readers.DatastoreInputReader”, output_writer_spec = “mapreduce.output_writers.FileOutputWriter”, params = { “input_reader”: { “entity_kind”: entity_type, }, “output_writer”: { “filesystem”: “gs”, “gs_bucket_name”: GS_BUCKET, “output_sharding”: “none”, } }, shards=SHARDS) yield CloudStorageToBigQuery(output) class CloudStorageToBigQuery(base_handler.PipelineBase): def run(self, files): table.name = ‘gplus_data_%s’ % datatime.utconv().strftime(...) jobs = bigquery.service.jobs() result = jobs.insert(projectId=Project_ID, body=build_job.data(table_name,files)).execute()

Page 126: Google Compute EngineとPipe API
Page 127: Google Compute EngineとPipe API

GAE + GCEのユースケース

Orchestrating Google Compute Engine through Google App Engine https://developers.google.com/events/io/sessions/gooio2012/308/

Page 128: Google Compute EngineとPipe API

Google App Engine + Google Compute Engine

Page 129: Google Compute EngineとPipe API

Video Sharing System

Page 130: Google Compute EngineとPipe API

Uploading Files

Page 131: Google Compute EngineとPipe API

Create task queue entry

Page 132: Google Compute EngineとPipe API

Task queue consumer

Page 133: Google Compute EngineとPipe API

Workload

Page 134: Google Compute EngineとPipe API

Shoe result

Page 135: Google Compute EngineとPipe API

Scaling

Page 136: Google Compute EngineとPipe API
Page 137: Google Compute EngineとPipe API
Page 138: Google Compute EngineとPipe API
Page 139: Google Compute EngineとPipe API
Page 140: Google Compute EngineとPipe API
Page 141: Google Compute EngineとPipe API
Page 142: Google Compute EngineとPipe API
Page 143: Google Compute EngineとPipe API
Page 144: Google Compute EngineとPipe API