Like what we’re doing? Star us on GitHub!

payload:build causing Out Of Memory exception in production

richardvanbergen
last year
1 1

I got a slight issue meaning that sometimes the application doesn't build on my DigitalOcean application.

I'm not sure if it's down to DigitalOcean but I've got a 4GB instance so I feel like that should be enough. I was just wondering if there is any way of limiting the amount of memory that payload:build consumes? Can I pass any node options to it?

  • jmikrut
    Payload Team
    last year

    Good question!

    I'm actually not sure, but we've seen similar issues with other Webpack projects in the past with DigitalOcean droplets. We solved our issues by using a swapfile:

    https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04

    I know they say that swapfiles cause SSD performance degradation, but they are a mainstay of *nix operating systems and I think DigitalOcean just says this in their own best interests. We have them running on most (all?) of our droplets.

    Otherwise, it looks like there are a bunch of ways to cap Node's memory usage, but I have never done it before.

    npm/npm#12238

    Maybe give some of those ideas a shot? I would be thrilled to hear what works!

    3 replies
  • richardvanbergen
    last year

    Thanks for the reply.

    There's a couple of issues with that.

    The first is that I'm not on a droplet. I'm using their app platform which is basically a managed droplet.

    The second is that I don't know what the underlying command for payload:build would be and how I could pass it parameters. Can I just pass it random node flags?

    I guess the other solution is to build the docker container on Github and just pull it down but I'm loathe to waste time on setting up docker registries and CI workflows for that. I was hoping I could just pass a magic --dont-run-out-of-memory-please flag.

  • jmikrut
    Payload Team
    last year

    Would these suggestions work?

    https://stackoverflow.com/questions/56982005/where-do-i-set-node-options-max-old-space-size-2048

    Looks like you can do it with an environment variable. Give that a shot?

  • richardvanbergen
    last year

    Perfect, I'll give it a shot in the morning. 😊

Open the post
Continue the discussion in GitHub
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More