【问题标题】:Meteor build running our of memory流星构建内存不足
【发布时间】:2017-03-09 19:24:53
【问题描述】:

我正在尝试构建我的流星应用程序并不断遇到以下错误。这不是我第一次构建应用程序,并且在昨天构建之前一切正常。我已经尝试过:正如 [this SO post][1] 中的答案之一所建议的那样,但它没有帮助。

#!/usr/bin/env node --max_old_space_size=4096 --optimize_for_size --max_executable_size=4096 --stack_size=4096

控制台输出:

meteor build .

WARNING: The output directory is under your source tree.
         Your generated files may get interpreted as source code!
         Consider building into a different directory instead
         meteor build ../output

   Minifying app code                        \
<--- Last few GCs --->

  103230 ms: Mark-sweep 1385.5 (1455.5) -> 1387.9 (1455.5) MB, 898.4 / 0 ms [allocation failure] [GC in old space requested].
  104206 ms: Mark-sweep 1387.9 (1455.5) -> 1387.9 (1455.5) MB, 975.8 / 0 ms [allocation failure] [GC in old space requested].
  105196 ms: Mark-sweep 1387.9 (1455.5) -> 1384.1 (1455.5) MB, 990.2 / 0 ms [last resort gc].
  106101 ms: Mark-sweep 1384.1 (1455.5) -> 1385.1 (1455.5) MB, 905.3 / 0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x249f6fdb4629 <JS Object>
    1: /* anonymous */(aka /* anonymous */) [0x249f6fd041b9 <undefined>:~4943] [pc=0xcd10dd2f48c] (this=0x249f6fd041b9 <undefined>,self=0x1400b413881 <an AST_ObjectKeyVal with map 0xc3d3a4651b9>,output=0x17417c4edd79 <an Object with map 0x16588927e021>)
    2: doit(aka doit) [0x249f6fd041b9 <undefined>:4190] [pc=0xcd10d7a3298] (this=0x249f6fd041b9 <undefined>)
    3: print [0x249f6fd041b9 <unde...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
Aborted (core dumped)

【问题讨论】:

    标签: node.js meteor


    【解决方案1】:

    同样的问题让我发疯,但我终于设法在流星 1.4.3.1 下解决了它。

    背景:

    问题是meteor调用节点来构建。运行时,节点会为其运行的 V8 引擎分配一定数量的内存。在较大的项目中,为 V8 分配的默认内存不足以跟踪所有内容 - 它在接近限制时尝试进行垃圾收集,但最终空间不足并崩溃并显示错误。

    如果我们只是直接运行 node,我们可以使用 --max-old-space-size 选项运行它,这将允许我们为 V8 引擎设置最大内存。问题在于,meteor 在自己的上下文中调用 node 并使用自己的选项,所以我们不能直接将标志添加到我们的流星调用中。

    解决方案:

    似乎meteor 1.4.3.1(可能还有其他)在调用节点时会传递TOOL_NODE_FLAGS环境变量中指定的标志和选项(其他人提到过NODE_OPTIONS,但它不适用于我的meteor-the标志只是被丢弃)

    所以如果要将节点引擎的最大内存增加到4 GB,请添加一个环境变量

    TOOL_NODE_FLAGS="--max-old-space-size=4096" 
    

    到您正在运行流星的上下文 - 该选项应传递给节点调用。

    (如果您不知道在哪里设置环境变量 - 它通常会在您的 IDE 构建配置或构建脚本中。如果您想彻底检查 --max-old... 选项是否真的是正在阅读,尝试将其更改为乱码 - 它应该会导致流星抛出错误)

    【讨论】:

    • 到目前为止,在我运行 meteor 之前,我通过在 shell 中运行以下行来直接干预节点的环境变量:#!/usr/bin/env node --max-old-space-size=2048 --gc-interval 300 但问题在于它并不保持一致。当我最终用完空间时,我仍然需要运行上述命令,然后重新启动流星。您的方法似乎有效,因为我现在看到节点(流星)消耗 > 1.6GB。我将稍微监控一下并接受您的回答。
    • 完美@Theodore。这行得通。作为健全性检查,我将 old-space-size 设置为 4,因此请注意应用程序立即崩溃。就像你说的那样。我接受并赞成这个答案。
    • 太棒了。我知道这对我来说是多么令人沮丧,所以我很高兴它对你有所帮助。
    【解决方案2】:

    您需要注意最初的警告:

    WARNING: The output directory is under your source tree.
             Your generated files may get interpreted as source code!
             Consider building into a different directory instead
             meteor build ../output
    

    阅读它所说的 - 基本上它会生成文件,然后编译它们。难怪它会遇到麻烦并耗尽内存。将构建放在不同的目录中(不在 Meteor 项目中),它应该会更快乐:)

    【讨论】:

      猜你喜欢
      • 2015-12-02
      • 1970-01-01
      • 1970-01-01
      • 2016-11-06
      • 2019-08-12
      • 2016-10-10
      • 2019-05-13
      • 2021-09-19
      • 1970-01-01
      相关资源
      最近更新 更多