Google I/O 報告

appengine ja night #16

Google App Engine 枠のセッション一覧

今回のアジェンダ

Leaving Preview and Pricing Change

Leaving Preview and Pricing Change

@tmatsuo さんの GTUG 東京 I/O 報告会の資料がとてもよく構成されています。

Building Enterprise Applications on App Engine

Pricing and Features

FAQ for out of preview pricing changes

Go on App Engine

Google App Engine 上で Go 言語を使えるようになりました (Experimental!)。

Python はどうなの?

結局、スピードの問題かな?

アプリの作り方

Go の標準 http パッケージを使う

func init() {
  http.HandleFunc("/", func(w http.ResponseWriter,
                            request *http.Request)
  {
    c := appengine.NewContext(request)
    fmt.Fprintf(w, "Hello, world! from %s", c.AppID())
  })
}

データストアの読み込み

type Greeting struct {
    Body    string
    Date    datastore.Time
}
func init() {
  http.HandleFunc("/", func(w http.ResponseWriter,
                            request *http.Request) {
    c := appengine.NewContext(request)
    greetings := &[]Greeting{}
    datastore.NewQuery("Greeting").
              Order("-Date").
              GetAll(c, greetings)
    //...
  })
}

データストアの書き込み

type Greeting struct {
    Body    string
    Date    datastore.Time
}
func init() {
  http.HandleFunc("/save", func(w http.ResponseWriter,
                            request *http.Request) {
    c := appengine.NewContext(request)
    g := &Greeting{
      Body: request.FormValue("body"),
      Date: datastore.SecondsToTime(time.Seconds()),
    }
    datastore.Put(c, datastore.NewIncompleteKey("Greeting"), g)
    http.Redirect(w, request, "/", http.StatusFound)
  })
}

Full Text Search

3年前に登録された Issue 217

Query

Sort

Pagination

3種類の仕組みが存在する

Core API

Document(
  doc_id = next_doc_id(),
  fields = [
    TextField(name="author", value=current_use().nickname()),
    HtmlField(name="comment", value=comment_value),
    DateField(name="published", value=datetime.date.today())
  ]
)
index = search_api.get_index(index_name)
response = index.search(SearchRequest(
  query='',
  cursor=response.cursor, limit=RESULTS_PER_PAGE)
  sort_specs=[
    SortSpec(expression='author', sort_descending=True, default_value='')
  ]))
scored_docs = []
for result in response:
  scored_docs.append((result.document, result.scores))

Datastore API

class Greeting(db.Model):
  author = db.UserProperty(searchType=ATOM)
  comment = db.StringProperty(multiline=True, searchType=HTML)
  date = db.DateTimeProperty(auto_now_add=true)
g = Greeting(author=current_user, comment='hello')
g_sync.put([search_index_mode=ASYNC_WRITE])
query = db.Query(Greeting)
query.matches('comment:hello AND author:alex@example.com')
results = query.fetch(limit=5)

REST API

URL GET POST DELETE
indexes meta-data
indexes/A meta-data create index A delete index A
indexes/A/docs get all docs delete all docs
indexes/A/docs/X get doc X create doc X delete doc X

Roadmap

段階的にリリースする模様?

現在は「REST APIの実装が始まったばかり」との事で、一般の開発者達がいつから使えるかは不明!

…とはいえ「既に動作している」事を強調していたし、期待しましょう。

App Engine Backends / Putting Task Queues to Work

Backends

FrontEnd(ユーザからのリクエスト)経由で起動される従来のインスタンスとは別にインスタンスを確保する事ができる。

30秒制限も10分制限も無い、時間制限無く処理を実行出来る。

2種類のインスタンスモード。

Backends

backends:
- name: memdb
  class: B8 # mem:1024mb, cpu:4.8GHz
  instances: 5
- name: tq
  options: dynamic
  instances: 10

queueの処理をbackendsで実行したり(処理時間は24h上限)。

taskqueue.add(url='/path/to/my/worker/'
  , params={'key': key}, target='tq')

Putting Task Queues to Work

QueueにPull Modeが追加. AppEngineが自動的にtaskを実行するのではなく、taskを明示的にpull(lease&delete)する。

queue:
- name: pull-queue
  mode: pull
  acl:
  - user_email: bar@foo.com
  - user_email: user@gmail.com

各種Google APIと同様に、API Explorer からも実行可能.

http://code.google.com/apis/explorer/#_s=taskqueue&_v=v1beta1

Putting Task Queues to Work

sdkを使ってRPCでpull(Lease/Delete)

q = taskqueue.Queue('worker-in-backends')
  tasks = q.lease_tasks(30, 100) // timeout:30sec, max:100tasks
  if not tasks:
    return
  for t in tasks:
    payload = t.payload
    # do something...
  q.delete_tasks(tasks)

small topics

Scaling App Engine - Advice on Making Your App Scale Better

The App Monitoring API

Trusted test program at http://goo.gl/xcB1E

MapReduce, Pipeline

資料作成が間に合いませんでしたすいません