r - 在带有Docker的Google App Engine Flex中使用水管工部署R时出错

标签 r docker google-app-engine plumber

在做什么?

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

使用RStudio的管道工的R代码在我的本地计算机上运行良好。但是现在我使用带有R的AI平台jupyter笔记本。我使用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应用程序部署(再次构建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"]

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看来,要使您的Apllication通过,它需要返回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"

关于r - 在带有Docker的Google App Engine Flex中使用水管工部署R时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57724224/

相关文章:

r - 从中提取表

node.js - Bcrypt 安装在 Docker 中失败

bash - 在 Docker 容器启动时启动 bash 脚本不起作用

java - 如何查看 JRE 和/或 GAE 类的调试日志

r - 是否可以使用包含字符向量(字符串)的变量命名 tibble 的列?

json - R data.frame 到带有子节点/分层结构的 JSON

r - 按组获取同比百分比变化

docker - 什么是Asp.net Core RC2 Dockerfile的正确ENTRYPOINT

jquery - 如何从 google app engine 返回一个值给 jquery?

php - 加速非常慢的 PHP 脚本生成大型 JSON 数组的速度