20

Problem:
I'm running out of RAM while performing the rake assets:precompile task in an automated build. Are there any strategies to do an incremental precompile, or in some other way perform the precompile stage without consuming as much RAM? It appears as though that task consumes around 850 MB more than the baseline for the build.

Context:
I'm trying to get a single Docker container Bitbucket Pipelines version of our automated build. Application stack includes Rails 4.2.7, PostgreSQL 9.3, Java 8, Maven 3.3.9 and JRuby 9.1.2.0. I've tried creating the image based off of Debian Jessie and also off of Alpine Linux, but it doesn't make much difference in the baseline memory.

4

2 回答 2

4

简短的回答

使用NodeJS作为预编译的 JavaScript 解释器(或另一个以低峰值 RAM 使用为特征的 JavaScript 解释器)。

更长的答案

对于上下文,与 therubyracer v0.12.2 和 therubyrhino v2.0.4 相比,我使用的是 NodeJS 4.5.0

你能增加内存吗?

听起来很愚蠢,但在使构建过程复杂化之前,看看是否有更多功能强大的构建机器可用,或者是否有交换空间可用(尽管它可能会增加构建时间)可能是有意义的。

你能切换 JavaScript 解释器吗?

高峰值 RAM 利用率似乎是therubyrhino(Mozilla 的 Rhino JavaScript 解释器)和therubyracer(V8 JavaScript 解释器)的基本特征。似乎没有一种有效的方法可以显着降低资产预编译阶段消耗的 RAM 量。正如@user4776684 所建议的那样,最可行的路径似乎是在构建生命周期之外预编译资产并将它们缓存在某处,以便可以获取它们而不是预编译它们。正如对该问题的评论所暗示的,Rails 版本和 Ruby 版本都有影响,但不如 JavaScript 解释器那么大。

如果一切都失败了

正如上面提到的 @slowjack2k,如果使用Bundler,可以利用并行配置来仅为预编译任务调用 NodeJS 并保持原始构建相对不变。我没有考虑这一点,因为切换解释器更容易,但是虽然我能够使用 rake 和 NodeJS 预编译资产,但在 rake + therubyrhino 调用时它们似乎没有被认为是预编译的,所以它们是重新预编译。我通过一个以编程方式设置的BUNDLE_GEMFILE环境变量实现了这一点,该变量指向一个完全独立的 gemfile,它使用 MRI Ruby 和 NodeJS 而不是 JRuby 和 therubyrhino。

于 2016-08-29T16:03:27.817 回答
0

我对 digitalocean 上最便宜的液滴也有类似的问题。我创建了 linux 交换分区。也许您的主要主机没有交换分区。

于 2016-08-15T19:28:51.390 回答