Docker进程挂起并被杀死

像这个话题一样,docker进程暂停并被杀死。 我的python项目运行bash脚本,其中的一个部分是运行R脚本,它从influxdb中提取数据,然后处理它。 当项目获得短时间的数据,例如1-5天时,这不是问题。 整个事情从几个星期的大时间框架开始。 它只是减慢,所以它需要年龄来产生任何东西(我检查日志),最终会被杀死。 R脚本可以取消大约25MB的数据,但70MB的数据并不那么容易。 难道Flask + bash + R会立即使用太多内存吗? 在Docker之外调用时,不会出现这样的问题

Dockerfile:

FROM ubuntu # Install requirements fot the flask app RUN apt-get clean && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && DEBIAN_FRONTEND=noninteractive apt-get install -y \ python3 \ python3-pip \ r-base \ r-base-dev \ r-cran-rgl \ mutt \ git \ texlive-fonts-recommended # Install requirements fot the flask app RUN pip3 install -r ./requirements.txt 

烧瓶应用程序的片段:

 @app.route('/send', methods=['POST']) def send(): path = os.path.dirname(os.path.realpath(__file__)) script = path + '/generate_pdf.sh' address = str(request.form['email']) start_date = convert_date(str(request.form['start_date'])) end_date = convert_date(str(request.form['end_date'])) command = [script, start_date, end_date, address] subprocess.run(command) return json.dumps({ 'status': 'OK', 'message': 'The action is completed' }) 

generate_pdf.sh:

 #!/bin/bash start_date="$1" end_date="$2" address="$3" DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" report_name="\"$DIR/my_document.pdf\"" R -e "rmarkdown::render('$DIR/generate_document.Rmd', output_file = $report_name)" --args "$start_date" "$end_date" report_name="$DIR/my_document.pdf" echo | mutt -s "Generated document" -a $report_name -- "$address" out=$(rm $report_name) 

R脚本片段:

 where.clause <- paste0("time >= '", start.date, "' AND time <= '", as.character(as.Date(end.date) + days(1)), "'") con <- influxdbr::influx_connection(host = "localhost", port = 8086, user = "root", pass = "root") select.query <- paste0( 'id, name, surname, car, employment_status' ) rows <- influx_select(con, db = 'my_db', select.query, from = 'workers', where = where.clause) rows <- as.data.frame(rows, stringsAsFactors = FALSE) if(is.data.frame(rows) && nrow(rows) == 0) { cat('No data could be obtained from the database.', sep = '\n') knitr::knit_exit() } 

以下是我在执行应用程序时得到的日志,假设要撤消大约74mb的数据。

 .... label: unnamed-chunk-4 (with options) List of 3 $ echo : logi FALSE $ message: logi FALSE $ warning: logi FALSE Success: (204) No Content /app/generate_pdf.sh: line 8: 58 Killed .... 

该应用程序可以在Docker外完美工作。

当调用这个命令rows <- influx_select原始版本获取数据。 在投入数据框之前,它的权重很大–24mb,70以上。

我手动运行docker里的脚本和R脚本走得更远一点:

 .... label: unnamed-chunk-8 (with options) List of 4 $ echo : logi FALSE $ message : logi FALSE $ fig.align : chr "left" $ fig.height: num 7 Quitting from lines 72-76 (generate_document.Rmd) Error in system(paste(which, shQuote(names[i])), intern = TRUE, ignore.stderr = TRUE) : cannot popen '/usr/bin/which 'pdfcrop' 2>/dev/null', probable reason 'Cannot allocate memory' ...