Google App Engine 標準環境 502 POST 伺服器錯誤

Google App Engine 標準環境 502 POST 伺服器錯誤

使用 App Engine 將資料從 Unity 串流傳輸到 PubSub 幾天后,我遇到了大量 502 錯誤,這增加了創建的實例數量,因此超出了每日支出限制。

實例增加

實例增加

我正在使用的Python腳本: https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard_python37/pubsub

所有錯誤都是 HTTP POST 請求,延遲時間大於 30 秒,日誌訊息為:

此請求導致您的應用程式啟動一個新進程,從而導致您的應用程式程式碼首次載入。因此,與應用程式的典型請求相比,此請求可能需要更長的時間並使用更多的 CPU。

建議我研究就緒性檢查和活性檢查,這些檢查僅在 Flex 環境中可用,但在標準環境中不可用。什麼可能導致此錯誤以及如何避免它們?

日誌範例:

    {
 httpRequest: {
  status: 502   
 }
 insertId: "5e2bf548000bc56fe5d27eec"  
 labels: {
  clone_id: "00c61b117c17d8ad1566cc1788d5763552dbe5ace0c77a3523e4047bdc431b306a3840a5168f"   
 }
 logName: "projects/x/logs/appengine.googleapis.com%2Frequest_log"  
 operation: {
  first: true   
  id: "5e2bf52700ff069deff4c6f3400001737e626f6f74796661726d6c697665000133000100"   
  last: true   
  producer: "appengine.googleapis.com/request_id"   
 }
 protoPayload: {
  @type: "type.googleapis.com/google.appengine.logging.v1.RequestLog"   
  appEngineRelease: "1.9.71"   
  appId: "s~x"   
  cost: 3.2186e-8   
  endTime: "2020-01-25T07:59:04.771274Z"   
  finished: true   
  first: true   
  host: "x.appspot.com"   
  httpVersion: "HTTP/1.1"   
  instanceId: "00c61b117c17d8ad1566cc1788d5763552dbe5ace0c77a3523e4047bdc431b306a3840a5168f"   
  instanceIndex: -1   
  ip: "x"   
  latency: "33.337627s"   
  line: [
   0: {
    logMessage: "This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application."     
    severity: "INFO"     
    time: "2020-01-25T07:59:04.770902Z"     
   }
  ]
  megaCycles: "4387"   
  method: "POST"   
  pendingTime: "0.005315345s"   
  requestId: "5e2bf52700ff069deff4c6f3400001737e626f6f74796661726d6c697665000133000100"   
  resource: "/"   
  responseSize: "288"   
  startTime: "2020-01-25T07:58:31.433647Z"   
  status: 502   
  traceId: "2ee7b458fad62565bd5ed150e67647fc"   
  traceSampled: true   
  urlMapEntry: "auto"   
  userAgent: "Dalvik/2.1.0 (Linux; U; Android 5.1.1; SM-T360 Build/LMY47X) x SDK"   
  versionId: "3"   
  wasLoadingRequest: true   
 }
 receiveTimestamp: "2020-01-25T07:59:04.772448343Z"  
 resource: {
  labels: {
   module_id: "default"    
   project_id: "x"    
   version_id: "3"    
   zone: "us12"    
  }
  type: "gae_app"   
 }
 severity: "INFO"  
 timestamp: "2020-01-25T07:58:31.433647Z"  
 trace: "projects/x/traces/2ee7b458fad62565bd5ed150e67647fc"  
 traceSampled: true  
}

應用.yaml:

runtime: python37
entrypoint: gunicorn -b :$PORT main:app

    #[START env]

        env_variables:
            PUBSUB_TOPIC: xx
            # This token is used to verify that requests originate from your
            # application. It can be any sufficiently random string.
            PUBSUB_VERIFICATION_TOKEN: xx
        #[END env]

要求.txt:

Flask==1.0.2
google-api-python-client==1.7.8
google-auth==1.6.3
google-cloud-pubsub==0.40.0
gunicorn==19.7.1

*注意:幾天后,儘管錯誤在日誌中仍然可見,但 AppEngine 儀表板上看不到增加的實例數量。

相關內容