API 云上的 Django Rest Framework 运行 正在关闭
API Django Rest Framework on Cloud Run shutting down
我已经在云 运行 上实施了 API DRF。 Dockerfile 如下:
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.7-slim
# Allow statements and log messages to immediately appear in the Cloud Run logs
ENV PYTHONUNBUFFERED True
# Prevents Python from writing pyc files to disc (equivalent to python -B option)
ENV PYTHONDONTWRITEBYTECODE True
ARG REQFILE=base.txt
ENV REQFILE ${REQFILE}
# install dependencies
RUN pip install --upgrade pip
# Copy application dependency manifests to the container image.
# Copying this separately prevents re-running pip install on every code change.
COPY requirements/*.txt ./
# Install production dependencies.
RUN pip install -r ./${REQFILE}
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
与文档中描述的相同:https://codelabs.developers.google.com/codelabs/cloud-run-django#6
但是几天后,我的代码没有任何重大变化,出现了以下错误:
因此,我的 API 上的某些查询非常慢(>60 秒)。通常,它们小于 500 毫秒。
这些关闭的原因是什么?
鉴于这种情况,这很可能与 Cloud Run Incident #20004:
Oct 29, 2020 13:12
: We are investigating an issue with Cloud Run deployments failing globally starting at Thursday, 2020-10-29 12:45 US/Pacific.
Oct 29, 2020 13:40
: Diagnosis: New deployments to Cloud Run will fail globally.
Oct 29, 2020 14:16
: The issue with Cloud Run deployments failing globally has been resolved for all affected projects as of Thursday, 2020-10-29 14:07 US/Pacific.
查看 Google Cloud Status Dashboard 以检查每个产品是否有 are/were 任何事件是非常值得的。
在本地测试我的 Docker 后没有发现任何错误或错误,我得出的结论是问题是由于云 运行 的冷启动引起的。
尽管我几个月前实施了一个解决方案(使用 Cloud Scheduler 在 Cloud 运行 上定期查询),但问题仍然存在。
我今天尝试了 implement a minimal number 个实例,目前是一个。
真正高延迟查询的数量下降到 0。
成本似乎不是很高(我会在月底评论价格,我预计大约 14 欧元),老实说,要解决这个问题,我会很容易地支付双倍的费用.
我已经在云 运行 上实施了 API DRF。 Dockerfile 如下:
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.7-slim
# Allow statements and log messages to immediately appear in the Cloud Run logs
ENV PYTHONUNBUFFERED True
# Prevents Python from writing pyc files to disc (equivalent to python -B option)
ENV PYTHONDONTWRITEBYTECODE True
ARG REQFILE=base.txt
ENV REQFILE ${REQFILE}
# install dependencies
RUN pip install --upgrade pip
# Copy application dependency manifests to the container image.
# Copying this separately prevents re-running pip install on every code change.
COPY requirements/*.txt ./
# Install production dependencies.
RUN pip install -r ./${REQFILE}
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
与文档中描述的相同:https://codelabs.developers.google.com/codelabs/cloud-run-django#6
但是几天后,我的代码没有任何重大变化,出现了以下错误:
因此,我的 API 上的某些查询非常慢(>60 秒)。通常,它们小于 500 毫秒。
这些关闭的原因是什么?
鉴于这种情况,这很可能与 Cloud Run Incident #20004:
Oct 29, 2020 13:12
: We are investigating an issue with Cloud Run deployments failing globally starting at Thursday, 2020-10-29 12:45 US/Pacific.
Oct 29, 2020 13:40
: Diagnosis: New deployments to Cloud Run will fail globally.
Oct 29, 2020 14:16
: The issue with Cloud Run deployments failing globally has been resolved for all affected projects as of Thursday, 2020-10-29 14:07 US/Pacific.
查看 Google Cloud Status Dashboard 以检查每个产品是否有 are/were 任何事件是非常值得的。
在本地测试我的 Docker 后没有发现任何错误或错误,我得出的结论是问题是由于云 运行 的冷启动引起的。 尽管我几个月前实施了一个解决方案(使用 Cloud Scheduler 在 Cloud 运行 上定期查询),但问题仍然存在。
我今天尝试了 implement a minimal number 个实例,目前是一个。 真正高延迟查询的数量下降到 0。
成本似乎不是很高(我会在月底评论价格,我预计大约 14 欧元),老实说,要解决这个问题,我会很容易地支付双倍的费用.