Forum Unusable due to "Can’t save in background: fork: Cannot allocate memory”

I’m using a 2GB Digital Ocean Droplet and I keep getting 500 errors when users are trying to post new comments.

I checked the server logs and I see them full of these 2 lines:

44:M 22 Feb 12:10:04.079 * 1 changes in 900 seconds. Saving…
44:M 22 Feb 12:10:04.079 # Can’t save in background: fork: Cannot allocate memory

Also, when I ssh into my droplet, I see that memory consumption is at 82%.

I tried updating everything to latest, resetting the machine, but nothing helps on the long run. It works ok for a bit an then starts throwing the errors again.

1 Like

Do you have swap configured? How big is your database?

2 Likes

@pfaffman No swap configured. I remember that when I deployed the forum 2 years ago it was required only for 1GB instances. Should I have swap?

The forum has 6.9k posts and I have 18.1 GB free on the server. Hope this info is enough, Otherwise, how can I check the db size?

The memory requirements have increased in the past couple years.

I’d see if swap space would solve your problem:

https://github.com/discourse/discourse_docker/blob/master/discourse-setup#L87-L93

6 Likes

Ok, I’ve made a swap now. Will update this after seeing how it goes. Thanks for the suggestion!

4 Likes

Even 1GB works fine, provided you have 2GB of swap, over a series of years running Discourse.

There are sometimes brief periods (usually during upgrades; it is strange to hear about this during regular use) where memory needs to be a bit larger.

It is definitely interesting to hear that no swap at all is affecting 2GB RAM instances cc @sam

2 Likes

@pfaffman The swap file seems to have fixed the issue so far. Thanks again!
@codinghorror Let me know if you would like me to provide any other details that could be helpful in case you would like to investigate the possible cause. And thanks all for this great platform!

Btw, this is what I get now when running “free -h”

The swap used memory has been increasing in size since yesterday. Maybe there is some memory leak?

Is your site very busy? What does the /about page show for stats? It’s possible your site is just very popular and thus needs more resources.

Hi,

Sorry to bring this up from Februrary but whanted to ask if it’s normal to have intermittent Error 500 with ~80% memory usage (like the OP).

The site is under heavy usage, but just wanted to know if there is some kind of “estimations” for a correlation Users/VolumeOfTraffic - Memory.

I saw that a “Swap” was recommended, pardon my ignorance, but how do you achieve that, it’s recommended? Or is like removing the incorporated Rate Limiter (which was not recommended by Sam)

I’m running the latest version of Discourse.

If you search the #howto category here there is a topic about adding swap. Running without swap is definitely not recommened, unless you have well over 2GB of RAM on your server already allocated to Discourse.

That doesn’t mean anything. How many page views per day/week/month?

You need enough RAM for your database to fit in memory. How big is your database, or how many posts are there?

How much RAM do you have? How fast is the CPU? Where are you hosted?

I am also getting 500 error as a member on other forum

There are many reasons that might happen. If you’re not the admin of the forum, there’s nothing you can do.

If you are the admin, then you can check memory and disk space and see if you have any broken plugins.

3 Likes