Ghost ends up using all 1GB memory of my VPS

Hello, I am kind of new to ghost, especially configuring and hosting it on my VPS. I managed to install it easily with the use of the CLI and following the guide.

  • What’s your URL? My site is at chadfernandez.xyz
  • What version of Ghost are you using? I’m running Ghost 4.6.4
  • How was Ghost installed and configured? I installed Ghost in an Oracle VPS with 1 OCPU and 1 GB of memory using Ghost-CLI version: 1.17.3.
  • What Node version, database, OS & browser are you using? Node is v14.17.0, MySQL is 8.0.25, OS is Ubuntu 20.04.1, and my browser is Brave.

My problem with my site is that I am experiencing some high memory usage, with my 1GB memory VPS, after a restart, it will go and take 80% of the memory, then even it’s just me tinkering with the site, it sometimes slowly rose to 90%, then eventually end up using all the memory that the thing just broke.

I did some digging into what I can do to lower memory usage, and I tried lowering memory usage of MySQL using this guide I found. And from around 300MB, MySQL now uses 193MB max (on paper).

Then on to htop I get this

note: I scrolled down a bit since the top used by the same MySQL process, which I counted is around 40-50 times in total.

Is there a fix, or some way that I can fix this? I’m just hosting the said site, and nothing else on this VPS.

Thank you.

3 Likes

Not sure if I can really help here but I’d suggest upgrading to 2gb ram, you don’t want your site crashing when you have 10 visitors. Plus a 2gb ram server is normally 7 - 10 dollars.

swap space could be an option as well…

Yeah, good idea. Taken a break from working with Ghost. But adding a swap file helped in my case. And I was thinking of just using Ghost in this vps as a headless cms, so if the (admin) site slows down, the production site will not be affected that much.

And I’m looking to integrate Ghost with Astro.

@chof64 can you confirm if the issue is resolved? I am still grappeling with this issue with exact same thing like you - only the ghost site and nothing else. 1GB ram and ghost just eats this up. Running the latest version.

Can you please help with the step by step resolution?

1 Like

Hello, @jackdaniel, so the issue I had was running out of memory, that’s why my VPS just won’t respond anymore (basically it crashes). So I did some tinkering, with the MySQL (forgot what steps I did) to reduce the memory usage, but no joy.

Then what I ended up doing was adding a swap file (read it somewhere). A swap file is exactly what the name says, it’s a file that your system use as a memory for times when you ran out of memory (depends on how you set it up).

But note that a swap file is way slower than ram, and it would be very slow if used from HDD than SSD, this is because of read/write speeds (read why → ).

I’ve used the linuxize guide when I created mine. But I suggest reading both to understand it fully.

1 Like

Thanks @chof64 for the resources - but is the problem resolved? I had tried using a swap file but the issue of ghost taking up entire memory (1GB) is still there.

Your htop output is showing a lot of Ghost processes, how many sites are you running?

Do you perform a lot of image uploads? Some Linux memory managers have issues freeing memory in that case

Yeah. I believe it was solved, the site slows down when on swap tho, but that’s no problem as I’ll just use it as Headless CMS.

I’m just running 1 ghost site.

Not much image uploads. It was just a gif for background, and icon image, and a few image insert on posts (around 2-4). I was however doing some page creation and post creation.

How do you set up jemalloc as memory allocator?

I’ve only just started using Ghost and will be using lots of images, I’m already finding that memory is getting full quickly all the time with only a handful uploaded. I’ve added a swap file. I had to start the site again from scratch after the droplet crashed and I could not reboot.

many thanks :)

So I installed jemalloc, but I’m still getting memory fixed at 75% whilst idle (I’ve got 1GB), is that normal?

@Kevin I am running 1 single site. My posts have 3-4 images per post and that’s about it. Overall 12-15 posts are there, I am still facing this issue. Some resolution here would really be helpful as the swap thing did not work for me.

@Carnarts which tutorial did you follow?

actually I just realised I’m not even sure if I’ve installed it properly, I installed the jemalloc library but maybe that’s not actually installed the allocator. I just followed this:

Although I do seem to be running ok at the moment and memory seems to be averaging 60% but might be a coincidence…

Yeah, I’ve tried installing it before, I’m not even sure if it was installed properly. I assume it was installed since Oracle Metrics went offline after the restart. But it hasn’t really improved that much memory management.

I tried it and it still does not reduce the memory consumption. Some official solution would really be helpful @Kevin sir.

The thing with swap file, it doesn’t reduce memory consumption. It helps prevent out of memory problems, just put it an extra kind of ram, which is not as fast as ram, but works. Basically trading speed for making your site up.

What you can do if you’re using this, is to just use ghost as a headless cms, and just build your main site (the one you’re visitors interact with) with jamstack, like Nextjs, Gatsby, etc. This might need some coding, but will make your site faster, and less likely to go down since it’ll be cached by servers