在 Google App Engine Flex 和 Docker 中使用 plumber 部署 R 时出错
Error while deploying R using plumber in Google App Engine Flex with Docker
在做什么?
我正在尝试使用 docker 容器在 Google App Engine Flex 上部署 R 模型。我最终的 objective 是将模型作为 API。使用水管工和 docker 容器部署应用程序时出现错误。
R 代码与管道工 运行 在我使用 RStudio 的本地计算机上很好。但是现在我正在使用带有 R 的 AI 平台 jupyter 笔记本。我使用 Docker 运行 image-name 命令在本地测试了 docker 并且我收到了一次以下消息 Docker 运行.
Starting server to listen on port 8080
当我在本地 Rstudio 中 运行 R + plumber 代码时,我收到以下消息
Starting server to listen on port 8080
Running the swagger UI at http://127.0.0.1:8080/__swagger__/
在此之后我 运行 gcloud app deploy(这再次构建 docker 图像等),构建 运行s 超过 15分钟并失败并显示错误消息,如最后所示。
代码等详情:
app.yaml
service: iris-custom
runtime: custom
env: flex
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 20
# added below to increase app_start_timeout_sec
readiness_check:
path: "/readiness_check"
check_interval_sec: 5
timeout_sec: 4
failure_threshold: 2
success_threshold: 2
app_start_timeout_sec: 900
Docker文件
FROM gcr.io/gcer-public/plumber-appengine
# install the linux libraries needed for plumber
RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update \
&& apt-get install -y
# install plumber commented as plumber is preinstalled
#RUN R -e "install.packages(c('plumber'), repos='http://cran.rstudio.com/')"
# copy everything from the current directory into the container
WORKDIR /payload/
COPY [".", "./"]
# open port 8080 to traffic
EXPOSE 8080
# when the container starts, start the main.R script
ENTRYPOINT ["Rscript", "main.R"]
main.R
library(plumber)
r <- plumb("rest_controller.R")
r$run(port=8080, host="0.0.0.0")
rest_controller.R
#* @get /predict_petal_length
get_predict_length <- function(){
dataset <- iris
# create the model
model <- lm(Petal.Length ~ Petal.Width, data = dataset)
petal_width = "0.4"
# convert the input to a number
petal_width <- as.numeric(petal_width)
#create the prediction data frame
prediction_data <- data.frame(Petal.Width=petal_width)
# create the prediction
predict(model,prediction_data)
}
错误信息:
ERROR: (gcloud.app.deploy) Error Response: [4] Your deployment has
failed to become healthy in the allotted time and therefore was rolled
back. If you believe this was an error, try adjusting the
'app_start_timeout_sec' setting in the 'readiness_check' section.
我尝试了一点修改代码,部署成功但应用引擎仍然无法运行。
issue with code link
从 Google Cloud Doku 看来,为了让您的应用程序通过,它需要 return http 状态代码 200(参见 https://cloud.google.com/appengine/docs/flexible/custom-runtimes/configuring-your-app-with-app-yaml#updated_health_checks)。
但是您的应用程序 return 在您为 redincess 检查定义的路径上的 http 状态代码 404,因为它不存在。
readiness_check:
path: "/readiness_check"
所以我建议将此路径作为一个选项添加到您的 rest_controller.R 文件中,例如
#* @get /readiness_check
readiness_check<- function(){
return ("app ready")
}
或修改您的 app.yml 以便它检查 get_predict_length enpoint
readiness_check:
path: "/get_predict_length"
在做什么?
我正在尝试使用 docker 容器在 Google App Engine Flex 上部署 R 模型。我最终的 objective 是将模型作为 API。使用水管工和 docker 容器部署应用程序时出现错误。
R 代码与管道工 运行 在我使用 RStudio 的本地计算机上很好。但是现在我正在使用带有 R 的 AI 平台 jupyter 笔记本。我使用 Docker 运行 image-name 命令在本地测试了 docker 并且我收到了一次以下消息 Docker 运行.
Starting server to listen on port 8080
当我在本地 Rstudio 中 运行 R + plumber 代码时,我收到以下消息
Starting server to listen on port 8080
Running the swagger UI at http://127.0.0.1:8080/__swagger__/
在此之后我 运行 gcloud app deploy(这再次构建 docker 图像等),构建 运行s 超过 15分钟并失败并显示错误消息,如最后所示。
代码等详情:
app.yaml
service: iris-custom
runtime: custom
env: flex
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 20
# added below to increase app_start_timeout_sec
readiness_check:
path: "/readiness_check"
check_interval_sec: 5
timeout_sec: 4
failure_threshold: 2
success_threshold: 2
app_start_timeout_sec: 900
Docker文件
FROM gcr.io/gcer-public/plumber-appengine
# install the linux libraries needed for plumber
RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update \
&& apt-get install -y
# install plumber commented as plumber is preinstalled
#RUN R -e "install.packages(c('plumber'), repos='http://cran.rstudio.com/')"
# copy everything from the current directory into the container
WORKDIR /payload/
COPY [".", "./"]
# open port 8080 to traffic
EXPOSE 8080
# when the container starts, start the main.R script
ENTRYPOINT ["Rscript", "main.R"]
main.R
library(plumber)
r <- plumb("rest_controller.R")
r$run(port=8080, host="0.0.0.0")
rest_controller.R
#* @get /predict_petal_length
get_predict_length <- function(){
dataset <- iris
# create the model
model <- lm(Petal.Length ~ Petal.Width, data = dataset)
petal_width = "0.4"
# convert the input to a number
petal_width <- as.numeric(petal_width)
#create the prediction data frame
prediction_data <- data.frame(Petal.Width=petal_width)
# create the prediction
predict(model,prediction_data)
}
错误信息:
ERROR: (gcloud.app.deploy) Error Response: [4] Your deployment has failed to become healthy in the allotted time and therefore was rolled back. If you believe this was an error, try adjusting the 'app_start_timeout_sec' setting in the 'readiness_check' section.
我尝试了一点修改代码,部署成功但应用引擎仍然无法运行。 issue with code link
从 Google Cloud Doku 看来,为了让您的应用程序通过,它需要 return http 状态代码 200(参见 https://cloud.google.com/appengine/docs/flexible/custom-runtimes/configuring-your-app-with-app-yaml#updated_health_checks)。
但是您的应用程序 return 在您为 redincess 检查定义的路径上的 http 状态代码 404,因为它不存在。
readiness_check:
path: "/readiness_check"
所以我建议将此路径作为一个选项添加到您的 rest_controller.R 文件中,例如
#* @get /readiness_check
readiness_check<- function(){
return ("app ready")
}
或修改您的 app.yml 以便它检查 get_predict_length enpoint
readiness_check:
path: "/get_predict_length"