# my\_app ran out of memory and crashed

**URL:** <https://community.fly.io/t/my-app-ran-out-of-memory-and-crashed/12667>\
**Category:** Questions / Help\
**Tags:** elixir, login-only\
**Created:** [May 3, 2023, 12:49am UTC](https://community.fly.io/t/my-app-ran-out-of-memory-and-crashed/12667 "2023-05-03T00:49:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mathiasn](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/mathiasn/32/35151_2.png) [@mathiasn](https://community.fly.io/u/mathiasn)\
**Post date:** [May 3, 2023, 12:49am UTC](https://community.fly.io/t/my-app-ran-out-of-memory-and-crashed/12667/1 "2023-05-03T00:49:28Z")

</div>

Hello,

I get these kind of email every 2 days or so. Sometimes on our Elixir app (up2date Phoenix with LiveView), sometimes on the Postgres App…

```auto
Out of memory: Killed process 520 (beam.smp) total-vm:1677288kB, anon-rss:393412kB, file-rss:0kB, shmem-rss:114180kB, UID:65534 pgtables:1300kB oom_score_adj:0

```

The raw total vm amount is pretty high, but I am wondering why I cannot see it on the metrics page directly in Fly or in Grafana:

_(it crashed 17:13)_  
 ![Screenshot 2023-05-02 at 17.34.26](https://global.discourse-cdn.com/fly1/original/3X/4/6/4666898907f5c188aeed5099c502d27cf299a826.png)

 ![Screenshot 2023-05-02 at 17.34.41](https://global.discourse-cdn.com/fly1/original/3X/b/2/b220b01d5a658a2703b56247778a0d3f8ee5ebbb.png)

Any hints how to debug that? Thanks a lot!

---

<div class="post-metadata">

**Author:** ![tj1](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@tj1](https://community.fly.io/u/tj1)\
**Post date:** [May 3, 2023, 1:31am UTC](https://community.fly.io/t/my-app-ran-out-of-memory-and-crashed/12667/2 "2023-05-03T01:31:34Z")

</div>

1. You can’t see it on metrics due to sampling. Probably a single request causing this.

1. It could be argon2 settings.

[https://elixirforum.com/t/staging-environment-how-to-debug-out-of-memory-errors-in-production-on-fly-io/42763/2](https://elixirforum.com/t/staging-environment-how-to-debug-out-of-memory-errors-in-production-on-fly-io/42763/2)

1. You could add some swap space by having a custom entrypoint script.

```auto
if [$UID -eq 0]; then
  fallocate -l 1024M /swapfile
  chmod 0600 /swapfile
  mkswap /swapfile
  echo 10 > /proc/sys/vm/swappiness
  swapon /swapfile
  echo 1 > /proc/sys/vm/overcommit_memory
fi
exec /app/bin/server

```

---

<div class="post-metadata">

**Author:** ![mathiasn](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/mathiasn/32/35151_2.png) [@mathiasn](https://community.fly.io/u/mathiasn)\
**Post date:** [May 3, 2023, 4:14am UTC](https://community.fly.io/t/my-app-ran-out-of-memory-and-crashed/12667/3 "2023-05-03T04:14:09Z")

</div>

Thanks for your reply!

We’re not using argon2 as we don’t have user/passwords.

Is it common best practice to use swap on machines like that?

---

<div class="post-metadata">

**Author:** ![tj1](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@tj1](https://community.fly.io/u/tj1)\
**Post date:** [May 3, 2023, 4:41am UTC](https://community.fly.io/t/my-app-ran-out-of-memory-and-crashed/12667/4 "2023-05-03T04:41:23Z")

</div>

Best practice? Not sure.

I do it to avoid random OOM’s on my staging machine which has very little memory, but zero load. Wouldn’t want to be swapping in production though.

---

<div class="post-metadata">

**Author:** ![mathiasn](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/mathiasn/32/35151_2.png) [@mathiasn](https://community.fly.io/u/mathiasn)\
**Post date:** [May 3, 2023, 4:51am UTC](https://community.fly.io/t/my-app-ran-out-of-memory-and-crashed/12667/5 "2023-05-03T04:51:57Z")

</div>

Just found that it’s even mentioned in the [docs](https://fly.io/docs/rails/cookbooks/deploy/#enabling-swap). [That](https://community.fly.io/t/swap-memory/2749) was also helpful.

---

<div class="post-metadata">

**Author:** ![ben-io](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/ben-io/32/35648_2.png) [@ben-io](https://community.fly.io/u/ben-io)\
**Post date:** [May 3, 2023, 5:21am UTC](https://community.fly.io/t/my-app-ran-out-of-memory-and-crashed/12667/6 "2023-05-03T05:21:51Z")

</div>

Of course, you can also just increase the VM memory size with `fly scale memory 512`.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [May 10, 2023, 5:22am UTC](https://community.fly.io/t/my-app-ran-out-of-memory-and-crashed/12667/7 "2023-05-10T05:22:06Z")

</div>

Closed on May 10, 2023, 5:22am UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
