我正在為該專案使用 golang 和 Google App Engine。我有一個任務,我收到了一個巨大的檔案,將它分成幾行,然后將這些行一一發送到佇列中進行決議。我在 app.yaml 檔案中縮放的初始設定如下:
instance_class: F1
automatic_scaling:
min_instances: 0
max_instances: 4
min_idle_instances: 0
max_idle_instances: 1
target_cpu_utilization: 0.8
min_pending_latency: 15s
它作業正常,但有一個問題——因為確實有很多任務,10 分鐘后它會失敗(當然,根據檔案)。所以我決定使用B1實體類而不是F1- 這就是事情出錯的地方。
我的 B1 設定如下所示:
instance_class: B1
basic_scaling:
max_instances: 4
現在,我創建了一個非常簡單的演示來演示這個想法:
r.GET("foo", func(c *gin.Context) {
_, err := tm.CreateTask(&tasks.TaskOptions{
QueueID: "bar",
Method: "method",
PostBody: "foooo",
})
if err != nil {
lg.LogErrorAndChill("failed, %v", err)
}
})
r.POST("bar/method", func(c *gin.Context) {
data, err := c.GetRawData()
if err != nil {
lg.LogErrorAndPanic("failed", err)
}
fmt.Printf("data is %v \n", string(data))
})
解釋它背后的邏輯:我向“foo”發送一個請求,它創建一個任務,該任務被添加到帶有一些正文的佇列中。在任務內部,一個 post 方法根據queueId和method引數被呼叫,它接收一些文本,在這個簡單的例子中只是將它注銷。
現在,當我運行請求時,出現 500 錯誤,如下所示:
[GIN] 2021/10/05 - 19:38:29 | 500 | 301.289μs | 0.1.0.3 | GET "/_ah/start"
在日志中我可以看到:
Process terminated because it failed to respond to the start request with an HTTP status code of 200-299 or 404.
并在任務佇列中(重試的原因):
INTERNAL(13): Instance Unavailable. HTTP status code 500
現在,我已經閱讀了檔案,并且了解了以下內容:
Manual, basic, and automatically scaling instances startup differently. When you start a manual scaling instance, App Engine immediately sends a /_ah/start request to each instance. When you start an instance of a basic scaling service, App Engine allows it to accept traffic, but the /_ah/start request is not sent to an instance until it receives its first user request. Multiple basic scaling instances are only started as necessary, in order to handle increased traffic. Automatically scaling instances do not receive any /_ah/start request.
When an instance responds to the /_ah/start request with an HTTP status code of 200–299 or 404, it is considered to have successfully started and can handle additional requests. Otherwise, App Engine terminates the instance. Manual scaling instances are restarted immediately, while basic scaling instances are restarted only when needed for serving traffic
但這并不是很有幫助 - 我不明白為什么/_ah/start請求沒有正確回應,我不確定如何除錯它或如何修復它,尤其是因為F1實體作業正常。
uj5u.com熱心網友回復:
對 url 的請求/_ah/start/被路由到您的應用程式,您的應用程式顯然還沒有準備好處理它,這會導致 500 回應。檢查您的日志。
基本上,您的應用程式需要準備好接收帶有 url 的傳入請求/_ah/start/(類似于它已準備好處理對 url 的請求/foo/)。如果您在本地運行該應用程式,請嘗試打開此類 url(通過curl等)并查看回應。它需要以回應代碼 200-299 或 404 回應(如您參考的文本中所述),否則不會被視為成功啟動的實體。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/318989.html
上一篇:應用引擎 Postgresql收到“連接被拒絕”錯誤
下一篇:應用引擎入口點的目的是什么?
