# Out of memory errors with custom plugin

**URL:** https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777
**Category:** Self-hosting
**Tags:** server-resources
**Created:** [October 20, 2020, 6:56pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777 "2020-10-20T18:56:18Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![pelcami](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pelcami/32/59732_2.png) [@pelcami](https://meta.discourse.org/u/pelcami)
#### Post date: [October 20, 2020, 6:56pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/1 "2020-10-20T18:56:18Z")

</div>

Would someone provide instructions to configure memory allocation?

Given the sporadic kernel “out of memory”/dump messages, 3x increased swapping, and increasing application degraded response, it seems our app is sometimes running out of memory. Our system currently has 8GB mem and 2GB swap. Details below.

I have reviewed the instructions for adding more physical mem and swap at (["Cannot allocate memory" when upgrading](https://meta.discourse.org/t/cannot-allocate-memory-when-upgrading/44029)) but have not been able to find details about how to allocate it.

When it comes to mem configs, we are using all defaults. The system recovers after a few minutes, but with increased usage - we think it’s time to get educated about how to improve performance. I am, however, unsure of where and how to configure this. Increase memory allocated for the docker instance, or for number of ruby unicorns (or both)?

I’m a sysadmin with no ruby and limited docker experience - so pointing me in direction of the config file, and syntax to use will help greatly.

# Discourse 2.6.0 beta2 Ruby 2.3.1-2~ubuntu16.04.14 Ubuntu 16.04

 ![Screen Shot 2020-10-20 at 11.47.59 AM](https://global.discourse-cdn.com/meta/original/3X/7/e/7e43b61a7849ebaa06b8385389d692e1b6a81144.png)

 ![Screen Shot 2020-10-20 at 11.38.21 AM](https://global.discourse-cdn.com/meta/original/3X/3/2/3268ff15f42d3087cfe90b82559052e5e729c4ca.png)

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [October 20, 2020, 7:29pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/2 "2020-10-20T19:29:45Z")

</div>

How many unicorns are you running? It is set on your `/var/discourse/containers/app.yml` file.

---

<div class="post-metadata">

### Author: ![pelcami](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pelcami/32/59732_2.png) [@pelcami](https://meta.discourse.org/u/pelcami)
#### Post date: [October 20, 2020, 8:16pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/3 "2020-10-20T20:16:48Z")

</div>

Hi Rafael - In the “env” section of app.yml, I see we are configured to use 4.

 ![Screen Shot 2020-10-20 at 1.17.24 PM](https://global.discourse-cdn.com/meta/original/3X/4/d/4d3d66da9a339a59257d801d574cafa7186a882b.png)

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [October 20, 2020, 8:21pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/4 "2020-10-20T20:21:34Z")

</div>

Did you re-run `discourse-setup` after you upped your RAM? It will tweak the memory settings accordingly. You can also read the comments in `app.yml` and adjust them.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [October 20, 2020, 8:24pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/5 "2020-10-20T20:24:52Z")

</div>

Getting OoM with just 4 unicorns is really weird. This should use around 2GB, leaving 6 GB for the PG and Redis.

You need to investigate what process is consuming all the memory during an OoM event, this is not normal.

---

<div class="post-metadata">

### Author: ![Serge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/serge/32/197544_2.png) [@Serge](https://meta.discourse.org/u/Serge)
#### Post date: [October 20, 2020, 10:07pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/6 "2020-10-20T22:07:35Z")

</div>

Hi Rafael and team, my name is Serge and I work with mr. Happy Lee who just departed for long anticipated vacation so I’ll be working on this issue.

To add to description: The server was originally built with 8GB of RAM and 2GB swap. We did not upgrade it since then.

In the system log I can see evidence that Ruby is the process that consuming all the memory and causing kernel OoM

Killed process 2960 (ruby) total-vm:10031472kB, **anon-rss:7438148kB** , file-rss:0kB

I am not ruby expert so not sure how to see which process in ruby consuming that much of memory.

Any suggestions appreciated.

Thanks.

-Serge

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [October 20, 2020, 10:09pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/7 "2020-10-20T22:09:25Z")

</div>

Are you running any plugins in this Discourse install?

---

<div class="post-metadata">

### Author: ![Serge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/serge/32/197544_2.png) [@Serge](https://meta.discourse.org/u/Serge)
#### Post date: [October 20, 2020, 10:27pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/8 "2020-10-20T22:27:50Z")

</div>

We do run Scheduled Digest custom plugin, however it also runs on our two other installations and those have no issues.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [October 20, 2020, 10:46pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/9 "2020-10-20T22:46:33Z")

</div>

> [@Serge](#):
>
> Scheduled Digest custom plugin

Can you link that plugin source code repository here?

---

<div class="post-metadata">

### Author: ![Serge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/serge/32/197544_2.png) [@Serge](https://meta.discourse.org/u/Serge)
#### Post date: [October 21, 2020, 5:56pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/10 "2020-10-21T17:56:57Z")

</div>

Hi Rafael,

the plugin was paid for development by our organization, so unfortunately I am not allowed to expose the source code here. Also since the plugin works on other instances without an issue, this makes me thinking of increasing server memory resources for this particular one. The machine is a VM so I can easily double the memory amount and see if this will fix it.

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [October 21, 2020, 6:22pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/11 "2020-10-21T18:22:31Z")

</div>

Okay, good luck!

Not much we can do to debug code we can’t see from our side. You may want to setup [Prometheus exporter plugin for Discourse](https://meta.discourse.org/t/prometheus-exporter-plugin-for-discourse/72666) to follow metrics on your instance.

---

<div class="post-metadata">

### Author: ![Benjamin\_D](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/benjamin_d/32/277831_2.png) [@Benjamin\_D](https://meta.discourse.org/u/Benjamin_D)
#### Post date: [October 21, 2020, 6:31pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/12 "2020-10-21T18:31:55Z")

</div>

Are the other instances also running Ruby 2.3.1-2~ubuntu16.04.14 ?

maybe nothing relevant but:

> **[ManageIQ - The Path\[name\] to discovering a memory leak in Ruby](https://www.manageiq.org/blog/2018/02/the-pathname-to-discovering-a-memory-leak-in-ruby/)**
>
> tl;dr we found a memory leak inRuby… and it mostly wasn’t ourfault!

`so this was clearly a Ruby bug. We tested across multiple versions of Ruby and determined that only rubies 2.3.x and 2.4.x were exhibiting the leak (apparently this was fixed in Ruby 2.5.0 **** ).`

And the discourse readme asks for [Ruby 2.6+] 🙄

---

<div class="post-metadata">

### Author: ![Serge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/serge/32/197544_2.png) [@Serge](https://meta.discourse.org/u/Serge)
#### Post date: [October 21, 2020, 9:26pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/13 "2020-10-21T21:26:14Z")

</div>

Thanks! I’ll post an update when it settles down.

---

<div class="post-metadata">

### Author: ![Serge](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/serge/32/197544_2.png) [@Serge](https://meta.discourse.org/u/Serge)
#### Post date: [October 21, 2020, 9:28pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/14 "2020-10-21T21:28:01Z")

</div>

Hi Benjamin, the other instances also running Ruby 2.3.1-2~ubuntu16.04.14 , I’ll test an update to see if it not breaks our Docker setup.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [October 21, 2020, 10:02pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/15 "2020-10-21T22:02:23Z")

</div>

Ruby version is not relevant here

As long as you are using our official docker image you will use the correct supported version of discourse

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [October 22, 2020, 9:00pm UTC](https://meta.discourse.org/t/out-of-memory-errors-with-custom-plugin/167777/16 "2020-10-22T21:00:00Z")

</div>

This topic was automatically closed after 26 hours. New replies are no longer allowed.
