[英]Error while deploying R using plumber in Google App Engine Flex with Docker
在做什么
我正在尝试使用docker容器在Google App Engine Flex上部署R模型。 我的最终目标是将模型用作API。 使用管道工和Docker容器部署应用程序时出现错误。
使用RStudio的管道工的R代码在我的本地计算机上运行良好。 但是现在我将AI平台的jupyter笔记本与R一起使用。我使用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
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"]
主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”设置。
我尝试了一些修改后的代码,部署成功,但应用引擎仍然无法正常工作。 代码链接问题
为了使您的应用程序通过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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.