rails资产管道“无法分配内存 - nodejs”

时间:2022-06-26 04:27:52

we've just upgraded to Rails 3.2.5 from Rails 3.0.7 and using the assets-pipeline compilation on the fly for the staging server, but some times we face this exception !

我们刚刚从Rails 3.0.7升级到Rails 3.2.5,并为登台服务器动态使用资产管道编译,但有时我们会面临这个异常!

Showing /var/rails/appname/app/views/common/_my_partial.html.haml where line # raised:

Cannot allocate memory - nodejs /tmp/execjs20120613-17090-thoc8f.js 2>&1

Extracted source (around line #):

Trace of template inclusion: app/views/layouts/application.html.haml

Although nothing fancy or huge memory allocations is done in the coffeescripts or in the images folder for example !

虽然在coffeescripts或images文件夹中没有做任何奇特或巨大的内存分配!

Thanks...

谢谢...

5 个解决方案

#1


81  

It's simple to spend the three minutes (maybe two if you type fast) to add a swap file to your server.

花三分钟(如果你快速输入可能是两分钟)来简单地将交换文件添加到服务器中。

If you're running Ubuntu (not sure how well this works for other Linux flavors), just follow this tutorial from DigitalOcean:

如果您正在运行Ubuntu(不确定这对其他Linux版本有多好),请按照DigitalOcean的本教程进行操作:

https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04

https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04

Voila!

瞧!

#2


11  

Based on the tutorial link provided by Kyle Carlson

基于Kyle Carlson提供的教程链接


Check swap space

检查交换空间

sudo swapon -s

sudo swapon -s

An empty list will confirm that you have no swap files enabled:

空列表将确认您没有启用交换文件:

Filename Type Size Used Priority

文件名类型大小使用优先级

Create and Enable the Swap File (swapfile)

创建并启用交换文件(交换文件)

sudo dd if=/dev/zero of=/swapfile bs=1024 count=256k

sudo dd if = / dev / zero of = / swapfile bs = 1024 count = 256k

Create a linux swap area:

创建一个linux交换区域:

sudo mkswap /swapfile

sudo mkswap / swapfile

output:

输出:

Setting up swapspace version 1, size = 262140 KiB no label, UUID=103c4545-5fc5-47f3-a8b3-dfbdb64fd7eb

Activate the swapfile:

激活交换文件:

sudo swapon /swapfile

sudo swapon / swapfile

check if you can see the swap summary.

检查您是否可以看到交换摘要。

swapon -s

Filename                Type        Size    Used    Priority
/swapfile                               file        262140  0   -1

Done!

完成!


To make the swap file permenant

使交换文件永久化

sudo nano /etc/fstab

sudo nano / etc / fstab

Paste in the following line:

粘贴在以下行:

/swapfile none swap sw 0 0

/ swapfile none swap sw 0 0

Swappiness in the file should be set to 10. Skipping this step may cause both poor performance, whereas setting it to 10 will cause swap to act as an emergency buffer, preventing out-of-memory crashes.

文件中的Swappiness应设置为10.跳过此步骤可能会导致性能不佳,而将其设置为10将导致交换充当紧急缓冲区,从而防止内存不足崩溃。

echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

set up the correct permissions on the swap file to not readable by the public:

在交换文件上设置正确的权限,使公众无法读取:

sudo chown root:root /swapfile 
sudo chmod 0600 /swapfile

#3


7  

Based on @tohi's answer, I created a script which you can paste into a terminal.

根据@ tohi的回答,我创建了一个可以粘贴到终端的脚本。

# Turn it (off) on
# sudo swapoff -a
sudo swapon -s

# Create a swap file
# 512k --> Swapfile of 512 MB
sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k

# Use the swap file
sudo mkswap /swapfile
sudo swapon /swapfile

# make sure the swap is present after reboot:
sudo echo " /swapfile       none    swap    sw      0       0 " >> /etc/fstab

# Set the swappiness (performance - aware)
echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf           

# Change the permission to non-world-readable
sudo chown root:root /swapfile 
sudo chmod 0600 /swapfile

Update: If you need to resize the /swapfile at a later point check out this answer: https://askubuntu.com/a/763717/508371

更新:如果您需要稍后调整/ swapfile的大小,请查看以下答案:https://askubuntu.com/a/763717/508371

#4


1  

We contacted the provider's support, and they are responded in 2 messages like this:

我们联系了提供商的支持,他们回复了2条消息,如下所示:

  1. There are two things that can be causing this: Either you are indeed running out of memory constantly or your Webby doesn’t have swap configured.
  2. 有两件事可能导致这种情况:您确实经常耗尽内存,或者您的Webby没有配置交换。

We have a sysadmin checking it and we’ll respond to your ticket soon.

我们有一个系统管理员检查它,我们很快就会回复您的机票。

  1. Your swap was disable for some reason, and that is why you were having memory issues. I fixed the fstab entry, and enable the swap on the right partition. You should be fine now.
  2. 您的交换由于某种原因被禁用,这就是您遇到内存问题的原因。我修复了fstab条目,并在右侧分区上启用交换。你现在应该没事。

And until now this error does not show :) Hope it will keep not showing for the future too ...

直到现在这个错误没有显示:)希望它将继续不显示未来...

Thanks, and best of LUCK ...

感谢和好运 ...

#5


0  

Maybe it helps to:

也许它有助于:

RAILS_ENV=production rake assets:clean

Restart your webserver / e.g.

重启您的网络服务器/例如

service apache2 restart

Then:

然后:

RAILS_ENV=production rake assets:precompile

#1


81  

It's simple to spend the three minutes (maybe two if you type fast) to add a swap file to your server.

花三分钟(如果你快速输入可能是两分钟)来简单地将交换文件添加到服务器中。

If you're running Ubuntu (not sure how well this works for other Linux flavors), just follow this tutorial from DigitalOcean:

如果您正在运行Ubuntu(不确定这对其他Linux版本有多好),请按照DigitalOcean的本教程进行操作:

https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04

https://www.digitalocean.com/community/articles/how-to-add-swap-on-ubuntu-12-04

Voila!

瞧!

#2


11  

Based on the tutorial link provided by Kyle Carlson

基于Kyle Carlson提供的教程链接


Check swap space

检查交换空间

sudo swapon -s

sudo swapon -s

An empty list will confirm that you have no swap files enabled:

空列表将确认您没有启用交换文件:

Filename Type Size Used Priority

文件名类型大小使用优先级

Create and Enable the Swap File (swapfile)

创建并启用交换文件(交换文件)

sudo dd if=/dev/zero of=/swapfile bs=1024 count=256k

sudo dd if = / dev / zero of = / swapfile bs = 1024 count = 256k

Create a linux swap area:

创建一个linux交换区域:

sudo mkswap /swapfile

sudo mkswap / swapfile

output:

输出:

Setting up swapspace version 1, size = 262140 KiB no label, UUID=103c4545-5fc5-47f3-a8b3-dfbdb64fd7eb

Activate the swapfile:

激活交换文件:

sudo swapon /swapfile

sudo swapon / swapfile

check if you can see the swap summary.

检查您是否可以看到交换摘要。

swapon -s

Filename                Type        Size    Used    Priority
/swapfile                               file        262140  0   -1

Done!

完成!


To make the swap file permenant

使交换文件永久化

sudo nano /etc/fstab

sudo nano / etc / fstab

Paste in the following line:

粘贴在以下行:

/swapfile none swap sw 0 0

/ swapfile none swap sw 0 0

Swappiness in the file should be set to 10. Skipping this step may cause both poor performance, whereas setting it to 10 will cause swap to act as an emergency buffer, preventing out-of-memory crashes.

文件中的Swappiness应设置为10.跳过此步骤可能会导致性能不佳,而将其设置为10将导致交换充当紧急缓冲区,从而防止内存不足崩溃。

echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf

set up the correct permissions on the swap file to not readable by the public:

在交换文件上设置正确的权限,使公众无法读取:

sudo chown root:root /swapfile 
sudo chmod 0600 /swapfile

#3


7  

Based on @tohi's answer, I created a script which you can paste into a terminal.

根据@ tohi的回答,我创建了一个可以粘贴到终端的脚本。

# Turn it (off) on
# sudo swapoff -a
sudo swapon -s

# Create a swap file
# 512k --> Swapfile of 512 MB
sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k

# Use the swap file
sudo mkswap /swapfile
sudo swapon /swapfile

# make sure the swap is present after reboot:
sudo echo " /swapfile       none    swap    sw      0       0 " >> /etc/fstab

# Set the swappiness (performance - aware)
echo 10 | sudo tee /proc/sys/vm/swappiness
echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf           

# Change the permission to non-world-readable
sudo chown root:root /swapfile 
sudo chmod 0600 /swapfile

Update: If you need to resize the /swapfile at a later point check out this answer: https://askubuntu.com/a/763717/508371

更新:如果您需要稍后调整/ swapfile的大小,请查看以下答案:https://askubuntu.com/a/763717/508371

#4


1  

We contacted the provider's support, and they are responded in 2 messages like this:

我们联系了提供商的支持,他们回复了2条消息,如下所示:

  1. There are two things that can be causing this: Either you are indeed running out of memory constantly or your Webby doesn’t have swap configured.
  2. 有两件事可能导致这种情况:您确实经常耗尽内存,或者您的Webby没有配置交换。

We have a sysadmin checking it and we’ll respond to your ticket soon.

我们有一个系统管理员检查它,我们很快就会回复您的机票。

  1. Your swap was disable for some reason, and that is why you were having memory issues. I fixed the fstab entry, and enable the swap on the right partition. You should be fine now.
  2. 您的交换由于某种原因被禁用,这就是您遇到内存问题的原因。我修复了fstab条目,并在右侧分区上启用交换。你现在应该没事。

And until now this error does not show :) Hope it will keep not showing for the future too ...

直到现在这个错误没有显示:)希望它将继续不显示未来...

Thanks, and best of LUCK ...

感谢和好运 ...

#5


0  

Maybe it helps to:

也许它有助于:

RAILS_ENV=production rake assets:clean

Restart your webserver / e.g.

重启您的网络服务器/例如

service apache2 restart

Then:

然后:

RAILS_ENV=production rake assets:precompile