Search code examples
node.jsmemoryprocessmeteordigital-ocean

Meteor is crashing on the smallest DigitalOcean Droplet (out of memory: Kill process ...)


I am running simple Meteor app on basic (512GB) DigitalOcean droplet. Once in a while Meteor simply crashes with this error message:

enter image description here

Out of memory: Kill process 9682 (node) ...
...
=> Exited from signal: SIGKILL
FATAL ERROR: JS Allocation failed - process out of memory

What is wrong? This is really simple app and it could not spend all the memory.


Solution

  • You can keep the smallest Droplet if you want. I had the same problem on my $5/mo DigitalOcean Droplet, 512MB RAM and 20 GB SSD. I did not upgrade but instead implemented swap as follows:

    Create and enable the swap file using the dd command:

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

    “of=/swapfile” designates the file’s name. In this case the name is swapfile.

    Next prepare the swap file by creating a linux swap area:

    sudo mkswap /swapfile
    

    The results display:

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

    Finish up by activating the swap file:

    sudo swapon /swapfile
    

    You will then be able to see the new swap file when you view the swap summary.

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

    This file will last on the virtual private server until the machine reboots. You can ensure that the swap is permanent by adding it to the fstab file.

    Open up the file:

    sudo nano /etc/fstab
    

    Paste in the following line:

     /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.

    You can do this with the following commands:

    echo 10 | sudo tee /proc/sys/vm/swappiness
    echo vm.swappiness = 10 | sudo tee -a /etc/sysctl.conf
    To prevent the file from being world-readable, you should set up the correct permissions on the swap file:
    
    sudo chown root:root /swapfile 
    sudo chmod 0600 /swapfile