在使用 App Engine 将数据从 Unity 流式传输到 PubSub 几天后,我遇到了大量 502 错误,这增加了创建的实例数量,因此超出了每日支出限额。
实例增加
我正在使用的 Python 脚本: https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard_python37/pubsub
所有错误都是 HTTP POST 请求,并且延迟大于 30 秒,日志消息为:
此请求导致您的应用程序启动新进程,从而导致首次加载您的应用程序代码。因此,此请求可能比您的应用程序的典型请求花费更长时间并使用更多 CPU。
有人建议我研究一下仅在 Flex 环境中可用但在 Standard 环境中不可用的就绪性检查和活性检查。什么可能导致此错误以及如何避免这些错误?
日志示例:
{
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 仪表板上却不可见。