[英]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.