basic_scaling の idle_timeout について #GAE

試したメモ。

app.yaml のドキュメントをみると、以下のように書いてある。

app.yaml#basic_scaling

idle_timeout
  Optional. The instance will be shut down this amount of time after receiving its last request. The default is 5 minutes.

  任意。 インスタンスは、最後の要求を受信した後、この時間をシャットダウンします。 デフォルトは5分です。(Google 翻訳)

受信とは…🤔

  1. 最後のリクエストを受け付けてからN分後にシャットダウンするのか
  2. 最後のリクエストを完了してからN分後にシャットダウンするのか

おそらく b だと思うけど、分からないので簡単に試した。

結論

b の最後のリクエストを完了してからN分後にシャットダウンする が正しい。

検証ログ

以下のように basic_scaling の設定をした app.yaml を用意して、

# app.yaml
... 略 ...

instance_class: B1
basic_scaling:
  idle_timeout: 1m # 5分だと長いので1分に設定
  max_instances: 1

handlers:
- url: /_ah/start # basic_scaling 用
  script: _go_app
  login: admin

- url: /path/to
  script: _go_app
  login: admin

... 略 ...

/path/to にアクセスする。

func PathTo(w http.ResponseWriter, req *http.Request) {
    ctx := appengine.NewContext(req)
    for i := 0; i < 20; i++ {
        log.Infof(ctx, "sleep... i:%v", i)
        time.Sleep(10 * time.Second)
    }
}

a であれば、最中にシャットダウンされるので、ログが途切れるハズ。

結果

f:id:utahta:20170709125158p:plain

途切れてない:)