Prisma + SQLite causes an out of memory error on deploy

My Remix app uses the solution outlined in this post, where the prisma migrations are run at app boot.

That solution works for me, but causes OOM on deploys with the 256MB instance, which is enough for running my app.

The OOM error happens when prisma is installed before the migration - logs below:

sea [info] + npx prisma migrate deploy
sea [info] npm WARN exec The following package was not found and will be installed: prisma@4.10.1
sea [info] [ 18.368134] Out of memory: Killed process 604 (node) total-vm:11174852kB, anon-rss:124780kB, file-rss:0kB, shmem-rss:0kB, UID:0 pgtables:1472kB oom_score_adj:0

Does anyone have ideas on how to avoid this OOM on deploy?

Also, I don’t have a great understanding of where the Fly.io experimental.cmd fits vs. the Dockerfile - why isn’t prisma already installed at that point?

Since the Remix indie stack recommends Fly.io, it would be sweet if it was possible to deploy an app under the hobby plan with 256MB of RAM.

2 Likes

Running into same problem - Basically everything on fly.io is broken lately - Really disappointing - I wasted so much time on this - was ready to host my app on a dedicated server but everything is so unreliable - I’ve wasted so much time, I feel like this whole app is one big sunk cost

I ended up scaling up and that seemed to work - another issue I had to deal with was just destroying one of my apps and rebuilding from scratch

1 Like

I had the same issue with the remix tutorial when deploying. You can add a swap file to help with the memory limit during the build.

Here is my start.sh file

set -ex

fallocate -l 512M /swapfile
chmod 0600 /swapfile
mkswap /swapfile
echo 10 > /proc/sys/vm/swappiness
swapon /swapfile
echo 1 > /proc/sys/vm/overcommit_memory
npx prisma migrate deploy
npm run start

i took the code from the fly.io docs : Optimizing your deployment · Fly Docs

3 Likes

@polkach Awesome. This helped a lot. I ended with this:

fallocate -l 256M /swapfile
chmod 0600 /swapfile
mkswap /swapfile
echo 10 > /proc/sys/vm/swappiness
swapon /swapfile
npx prisma migrate deploy
swapoff /swapfile
rm /swapfile
npm run start

I’m not sure if it’s necessary to turn the swap off and remove the allocated space. I figured that this would mean the prod app would be using the swapfile too (and thus would have less persistent storage). Does that sound right? I also removed the overcommit since I’m not sure it’s necessary here.

Hi @sastreen,

Is it in the entrypoint.sh ? Can you share your fly.toml as well ?

I currently have:

[deploy]
  release_command = "npx prisma migrate deploy"

But I feel I need to change that, correct ?