R GC() CMD 批处理执行时间上的垃圾收集
Posted
技术标签:
【中文标题】R GC() CMD 批处理执行时间上的垃圾收集【英文标题】:R GC() Garbage collection on CMD Batch execution time 【发布时间】:2017-06-26 18:55:00 【问题描述】:在服务器上执行 CMD 批处理时,R 脚本需要很长时间才能启动,这在 ROut 文件中得到了证实。 打开 Verbose 显示所有脚本的 GC 运行大约 10 分钟,这些脚本在 RStudio 中运行良好
这是任务调度程序中的命令行 C:\Program Files\R\R-3.3.2\bin\x64\R.exe” CMD BATCH "\Server-Directory\RFilename.R"
ROut 文件如下所示/ 正如我所说,在 RStudio 中运行时不会发生这种情况。
任何帮助将不胜感激
'verbose' and 'quietly' are both true; being verbose then ..
now dyn.load("C:/Program Files/R/R-3.3.2/library/methods/libs/x64/methods.dll") ...
R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an html browser interface to help.
Type 'q()' to quit R.
Garbage collection 1 = 0+0+1 (level 2) ...
5.4 Mbytes of cons cells used (29%)
1.4 Mbytes of vectors used (17%)
Garbage collection 2 = 0+1+1 (level 1) ...
15.6 Mbytes of cons cells used (83%)
7.4 Mbytes of vectors used (94%)
Garbage collection 3 = 0+1+2 (level 2) ...
17.4 Mbytes of cons cells used (71%)
7.9 Mbytes of vectors used (68%)
Garbage collection 4 = 0+1+3 (level 2) ...
23.0 Mbytes of cons cells used (73%)
10.5 Mbytes of vectors used (72%)
Garbage collection 5 = 0+1+4 (level 2) ...
27.2 Mbytes of cons cells used (68%)
11.7 Mbytes of vectors used (59%)
Garbage collection 6 = 0+1+5 (level 2) ...
27.2 Mbytes of cons cells used (54%)
17.9 Mbytes of vectors used (66%)
Garbage collection 7 = 0+1+6 (level 2) ...
27.2 Mbytes of cons cells used (54%)
27.2 Mbytes of vectors used (71%)
Garbage collection 8 = 0+1+7 (level 2) ...
27.2 Mbytes of cons cells used (54%)
36.5 Mbytes of vectors used (74%)
Garbage collection 9 = 0+1+8 (level 2) ...
27.2 Mbytes of cons cells used (54%)
49.0 Mbytes of vectors used (76%)
Garbage collection 10 = 0+1+9 (level 2) ...
27.4 Mbytes of cons cells used (54%)
63.5 Mbytes of vectors used (75%)
Garbage collection 11 = 0+1+10 (level 2) ...
27.4 Mbytes of cons cells used (54%)
80.3 Mbytes of vectors used (76%)
Garbage collection 12 = 0+1+11 (level 2) ...
27.4 Mbytes of cons cells used (54%)
102.6 Mbytes of vectors used (78%)
Garbage collection 13 = 0+1+12 (level 2) ...
27.4 Mbytes of cons cells used (54%)
130.4 Mbytes of vectors used (79%)
Garbage collection 14 = 0+1+13 (level 2) ...
29.3 Mbytes of cons cells used (58%)
164.4 Mbytes of vectors used (80%)
Garbage collection 15 = 0+1+14 (level 2) ...
33.9 Mbytes of cons cells used (54%)
204.1 Mbytes of vectors used (80%)
Garbage collection 16 = 0+1+15 (level 2) ...
33.9 Mbytes of cons cells used (54%)
248.8 Mbytes of vectors used (81%)
Garbage collection 17 = 1+1+15 (level 0) ...
62.5 Mbytes of cons cells used (100%)
300.4 Mbytes of vectors used (98%)
Garbage collection 18 = 1+1+16 (level 2) ...
62.5 Mbytes of cons cells used (81%)
298.4 Mbytes of vectors used (81%)
Garbage collection 19 = 1+1+17 (level 2) ...
63.2 Mbytes of cons cells used (67%)
364.6 Mbytes of vectors used (58%)
Garbage collection 20 = 1+1+18 (level 2) ...
94.6 Mbytes of cons cells used (82%)
541.5 Mbytes of vectors used (72%)
Garbage collection 21 = 1+1+19 (level 2) ...
115.7 Mbytes of cons cells used (82%)
562.3 Mbytes of vectors used (62%)
Garbage collection 22 = 1+1+20 (level 2) ...
140.9 Mbytes of cons cells used (82%)
577.8 Mbytes of vectors used (64%)
Garbage collection 23 = 1+1+21 (level 2) ...
171.2 Mbytes of cons cells used (82%)
595.1 Mbytes of vectors used (65%)
Garbage collection 24 = 1+1+22 (level 2) ...
207.6 Mbytes of cons cells used (83%)
615.9 Mbytes of vectors used (68%)
Garbage collection 25 = 1+1+23 (level 2) ...
251.3 Mbytes of cons cells used (83%)
656.9 Mbytes of vectors used (60%)
Garbage collection 26 = 1+1+24 (level 2) ...
303.6 Mbytes of cons cells used (83%)
686.9 Mbytes of vectors used (63%)
Garbage collection 27 = 1+1+25 (level 2) ...
366.5 Mbytes of cons cells used (83%)
722.8 Mbytes of vectors used (66%)
Garbage collection 28 = 1+1+26 (level 2) ...
441.9 Mbytes of cons cells used (83%)
798.1 Mbytes of vectors used (61%)
Garbage collection 29 = 1+1+27 (level 2) ...
532.4 Mbytes of cons cells used (83%)
850.1 Mbytes of vectors used (65%)
Garbage collection 30 = 1+1+28 (level 2) ...
641.0 Mbytes of cons cells used (83%)
912.6 Mbytes of vectors used (70%)
Garbage collection 31 = 1+1+29 (level 2) ...
771.4 Mbytes of cons cells used (83%)
987.8 Mbytes of vectors used (63%)
Garbage collection 32 = 1+1+30 (level 2) ...
927.8 Mbytes of cons cells used (83%)
1141.0 Mbytes of vectors used (60%)
Garbage collection 33 = 1+1+31 (level 2) ...
1115.5 Mbytes of cons cells used (83%)
1248.3 Mbytes of vectors used (66%)
Garbage collection 34 = 1+1+32 (level 2) ...
1261.6 Mbytes of cons cells used (78%)
1885.0 Mbytes of vectors used (83%)
【问题讨论】:
改用 Rscript.exe 吗? 您是否在同一台机器上运行 Rstudio?他们有相同数量的 RAM 吗?如果没有reproducible example,要帮助您并不容易。 机器有 32GB 内存,测试是在同一台机器上和另一台机器上进行的。我想知道在运行 CMD Batch 与 RStudio 时 Java 是否有区别?如果可以的话,我会分享代码,但这是在任何代码执行之前,所以我怀疑它会有所帮助。 刚刚尝试了一个空的脚本文件,结果相同。 RScript 没有这个问题。感谢 A.Webb 的建议 【参考方案1】:不是对 CMD BATCH 的修复,但 A.Webb 建议改用 RScript。 这有效,因为脚本现在执行得非常快,但它缺少 ROut 文件。
曾经: C:\Program Files\R\R-3.3.2\bin\x64\R.exe” CMD BATCH "\Server-Directory\RFilename.R"
现在: C:\Program Files\R\R-3.3.2\bin\x64\RScript.exe” "\Server-Directory\RFilename.R"
【讨论】:
以上是关于R GC() CMD 批处理执行时间上的垃圾收集的主要内容,如果未能解决你的问题,请参考以下文章