【问题标题】:Error while deploying R using plumber in Google App Engine Flex with Docker在带有 Docker 的 Google App Engine Flex 中使用管道工部署 R 时出错
【发布时间】:2019-08-30 09:38:29
【问题描述】:

在做什么?

我正在尝试使用 docker 容器在 Google App Engine Flex 上部署 R 模型。我的最终目标是将模型作为 API 服务。使用管道工和 docker 容器部署应用程序时出现错误。

带有管道工的 R 代码在我使用 RStudio 的本地计算机上运行良好。但现在我正在使用带有 R 的 AI 平台 jupyter notebooks。我使用 Docker Run image-name 命令在本地测试了 docker,一旦 Docker 运行,我会收到以下消息。

Starting server to listen on port 8080 

当我在本地 Rstudio 中运行 R + 管道工代码时,我收到以下消息

Starting server to listen on port 8080
Running the swagger UI at http://127.0.0.1:8080/__swagger__/

在此之后我运行 gcloud app deploy(这又是构建 docker 映像等),构建运行超过 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

Dockerfile

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"]

ma​​in.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)
}

错误信息:

错误:(gcloud.app.deploy) 错误响应:[4] 您的部署有 未能在规定的时间内恢复健康,因此被滚动 背部。如果您认为这是一个错误,请尝试调整 “readiness_check”部分中的“app_start_timeout_sec”设置。

我尝试了一些修改代码,部署成功,但应用引擎仍然无法工作。 issue with code link

【问题讨论】:

    标签: r docker google-app-engine plumber


    【解决方案1】:

    从 Google Cloud Doku 看来,为了让您的应用程序通过,它需要返回 http 状态代码 200(请参阅https://cloud.google.com/appengine/docs/flexible/custom-runtimes/configuring-your-app-with-app-yaml#updated_health_checks)。

    但是您的应用程序在您为重新检查定义的路径上返回 http 状态代码 404,因为它不存在。

    readiness_check:
     path: "/readiness_check"
    

    所以我建议将此路径作为选项添加到您的 rest_controller.R 文件中,例如

    #* @get /readiness_check
    readiness_check<- function(){
        return ("app ready")
    }
    

    或修改您的 app.yml 以改为检查 get_predict_length 端点

    readiness_check:
      path: "/get_predict_length"
    

    【讨论】:

    猜你喜欢
    • 2019-04-11
    • 1970-01-01
    • 2019-05-30
    • 2018-12-11
    • 2018-12-16
    • 2013-01-07
    • 1970-01-01
    相关资源
    最近更新 更多